本文為大家分享了C#程序啟動項的設(shè)置方法,供大家參考,具體內(nèi)容如下
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供洛龍網(wǎng)站建設(shè)、洛龍做網(wǎng)站、洛龍網(wǎng)站設(shè)計、洛龍網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、洛龍企業(yè)網(wǎng)站模板建站服務(wù),十余年洛龍做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。托盤圖標(biāo)設(shè)置
新建一個NotifyIcon,會在托盤處顯示一個圖標(biāo)。
NotifyIcon.Icon可以直接設(shè)置一個ico圖片,也可以延用原有程序的圖標(biāo)。
notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
public partial class MainWindow : Window { private NotifyIcon notifyIcon; public MainWindow() { InitializeComponent(); SetNotifyIcon(); this.Hide(); } #region NotifyIcon private void SetNotifyIcon() { this.notifyIcon = new NotifyIcon(); this.notifyIcon.BalloonTipText = "磁盤清理工具"; this.notifyIcon.ShowBalloonTip(2000); this.notifyIcon.Text = "磁盤清理工具:每20天清理一次"; this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath); this.notifyIcon.Visible = true; //打開菜單項 MenuItem open = new MenuItem("打開"); open.Click += new EventHandler(Show); //退出菜單項 MenuItem exit = new MenuItem("退出"); exit.Click += new EventHandler(Close); //關(guān)聯(lián)托盤控件 MenuItem[] childen = new MenuItem[] { open, exit }; notifyIcon.ContextMenu = new ContextMenu(childen); this.notifyIcon.MouseDoubleClick += new MouseEventHandler((o, e) => { if (e.Button == MouseButtons.Left) this.Show(o, e); }); } private void Show(object sender, EventArgs e) { this.Visibility = Visibility.Visible; this.ShowInTaskbar = true; this.Activate(); } private void Hide(object sender, EventArgs e) { this.ShowInTaskbar = false; this.Visibility = Visibility.Hidden; } private void Close(object sender, EventArgs e) { System.Windows.Application.Current.Shutdown(); } #endregion #region 窗口 private void MinimizeButton_OnClick(object sender, RoutedEventArgs e) { WindowState = WindowState.Minimized; } private void CloseButton_OnClick(object sender, RoutedEventArgs e) { this.Hide(); } private void HeaderGrid_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ButtonState == MouseButtonState.Pressed) { this.DragMove(); } } #endregion }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。