system.windows.fomrs.notifyicon类 system.windows.forms.contextmenu类 system.windows.forms.menuitem类 system.windows.forms.label类 system.windows.forms.timer类 |
private icon m_icon1; private icon m_icon2; private bool m_bflag; private bool m_bshowwnd; |
public form1() { // // required for windows form designer support // initializecomponent(); // // todo: add any constructor code after initializecomponent call // m_bflag=true; m_bshowwnd=true; try { m_icon1 = new icon("icon1.ico");//导入图标文件 m_icon2 = new icon("icon2.ico"); } catch ( exception e ) { messagebox.show("error " + e.message,"animate tray - error"); menuitem2.enabled = false; menuitem3.enabled = false; } } 添加menuitem1、menuitem2、menuitem3、m_trayicon的click事件,消息处理函数如下: private void menuitem1_click(object sender, system.eventargs e) { timer1.start();//打开计时器 } private void menuitem2_click(object sender, system.eventargs e) { timer1.stop();//停止计时器 } private void menuitem3_click(object sender, system.eventargs e) { application.exit();//退出应用程序 } private void m_trayicon_click(object sender, system.eventargs e) { if(m_bshowwnd == true)//隐藏主界面 { this.visible = false; m_bshowwnd = false; } else//显示主界面 { this.visible = true; m_bshowwnd = true; } } |
private void timer1_tick(object sender, system.eventargs e) { if ( m_icon1 != null && m_icon2 != null ) //如果两个图标文件都被正确载入 { //只要timer1被启动,则在两个图标之间不断进行选择变换,实现动画效果 if ( m_bflag == true ) { m_trayicon.icon = m_icon2; m_bflag = false; } else { m_trayicon.icon = m_icon1; m_bflag = true; } } } |
新闻热点
疑难解答