C#winform 里面怎样点击标题栏的关闭按钮后,窗口不关闭,而是最小化啊(象MSN一样),用于及时通讯的客户端程序里面,谢谢大家了

解决方案 »

  1.   

    Form的Closing事件:private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        this.Hide ();
        e.Cancel =true;
    }
      

  2.   

    为NotifyIcon控件添加Double_Click事件:
    private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
    {
    this.Show ();
    this.WindowState  =FormWindowState.Normal;
    }或者为NotifyIcon添加ContextMenu:
    this.contextMenu1 = new System.Windows.Forms.ContextMenu();
    this.menuItem1 = new System.Windows.Forms.MenuItem();
    this.menuItem2 = new System.Windows.Forms.MenuItem();
    this.notifyIcon1.ContextMenu = this.contextMenu1;
    // 
    // contextMenu1
    // 
    this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem2});
    // 
    // menuItem1
    // 
    this.menuItem1.Index = 0;
    this.menuItem1.Text = "打开";
    this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
    // 
    // menuItem2
    // 
    this.menuItem2.Index = 1;
    this.menuItem2.Text = "关闭";
    this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);private void menuItem1_Click(object sender, System.EventArgs e)
    {
    this.Show ();
    }private void menuItem2_Click(object sender, System.EventArgs e)
    {
    this.Close ();
    Application.Exit ();
    }