C#应用程序----系统托盘

1.新建一个窗体
2.在工具箱中找到三个控件分别是(mainMenu1,contextMenu1,notifyIcon1)
mainMenu1控件用于新建菜单
contextMenu1控件用于新建右击菜单
notifyIcon1控件用于新建托盘的图标

3选中窗体在将属性Menu设成mainMenu1,然后在窗体上新建菜单项

4设置notifyIcon1的ContextMenu属性将它设成contextMenu1用于右击
(还有其它属性可以自己测试)


5在Form_Load中写代码用于为contextMenu1生成菜单[写如下代码]

 

this .contextMenu1.MenuItems.Add( this .menuItem2.CloneMenu());
            
this .contextMenu1.MenuItems.Add( this .menuItem3.CloneMenu());
            
this .contextMenu1.MenuItems.Add( this .menuItem4.CloneMenu());
            
this .contextMenu1.MenuItems.Add( this .menuItem3.CloneMenu());
            
this .contextMenu1.MenuItems.Add( this .menuItem6.CloneMenu());


6为(托盘)菜单项写如下代码

 

this .Visible = false ;
            
this .notifyIcon1.Visible = true ;

 
7为(还原)菜单项写如下代码

 

this .Visible = true ;
            
this .notifyIcon1.Visible = false ;

8为(退出)菜单项写如下代码

 Application.Exit();

你可能感兴趣的:(C#应用程序----系统托盘)