使用NotifyIcon控件創建任務欄托盤

 

namespace NotifyIcon
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void Form1_Load(object sender, EventArgs e)
        
{
            
this.components = new Container();
            System.Windows.Forms.NotifyIcon notifyicon 
= new System.Windows.Forms.NotifyIcon(this .components );
            notifyicon.Text 
= "演示創建托盤";
            notifyicon.Visible 
= true;
            ResourceManager resourceManager 
= new ResourceManager("NotifyIcon.Properties.Resources", GetType().Module.Assembly);//從資源文件中添加圖標
            notifyicon.Icon = resourceManager.GetObject("icon1"as Icon;
            MenuItem menuitem 
= new MenuItem("退出程序");
            notifyicon.ContextMenu 
= new ContextMenu(new MenuItem[] { menuitem });
            menuitem.Click 
+= new EventHandler(menuitem_Click);
            notifyicon.MouseClick 
+= new MouseEventHandler(notifyicon_MouseClick);

        }


        
void notifyicon_MouseClick(object sender, MouseEventArgs e)
        
{
            
//throw new Exception("The method or operation is not implemented.");
            if (this.WindowState == FormWindowState.Minimized)
                
this.WindowState = FormWindowState.Normal;
        }


        
void menuitem_Click(object sender, EventArgs e)
        
{
            
//throw new Exception("The method or operation is not implemented.");
            Application.Exit();
        }

    }

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章