现在的位置: 首页 > 综合 > 正文

最小化或关闭窗体时,隐藏到系统托盘

2013年12月26日 ⁄ 综合 ⁄ 共 695字 ⁄ 字号 评论关闭
protected override void
OnClosing(CancelEventArgs e )
{
      this.WindowState =
FormWindowState.Minimized;         //窗体状态最小化
     
e.Cancel =
true;                                      //取消该事件,即取消onClosing事件
}

private
void contextMenuItemsClose_Click(object sender, System.EventArgs
e)
{
      Application.Exit();     //notify控件的 ContextMenu
中要设置一个“关闭程序”的项目,否则无法退出
}

//监视窗体状态,当最小化时,到系统托盘
private void Form1_Resize(object sender,System.EventArgs e)  
{   
     if(this.WindowState == FormWindowState.Minimized){  
          
this.Visible=false;   
           this.notifyIcon1.Visible   =  
true;   
     }else {   
           this.Visible   =  
true;   
           this.notifyIcon1.Visible   =  
false;                                   
      }   
}   

抱歉!评论已关闭.