C#Closing事件为何点击退出按钮不能关闭,我要的是那种点击退出弹出是否退出,现在点击退出不能退出。如果直接点击右上角“X”可以直接退出 而先点击退出在点击“X”才会弹出大家帮帮忙
  private void button5_Click(object sender, EventArgs e)
        {
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        }        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("是否要退出", "Application", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
            {
                e.Cancel = true;
            }        }

解决方案 »

  1.   


      if (MessageBox.Show("您确认要退出吗?", "退出系统", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    this.Dispose();
                   // Application.Exit();
                }
                else
                    e.Cancel = true;
      

  2.   

      private void button5_Click(object sender, EventArgs e)
       {
       this.Close();
       }
      

  3.   


      private void Form1_FormClosing(object sender, FormClosingEventArgs e)
      {
      if (MessageBox.Show("是否要退出", "Application", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
      {
      e.Cancel = true;
      }  }
    你让别人不确定退出  然后给别人退出?
      

  4.   

    楼主,这是我修改的程序,看看满意不
            public Form1()
            {
                InitializeComponent();
                this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
            }
            bool bClicked = false;
            private void button1_Click(object sender, EventArgs e)
            {
                bClicked = true;
            }        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                if (!bClicked)
                {
                    e.Cancel = false;
                    return;
                }
                if (MessageBox.Show("是否要退出", "Application", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                {
                    e.Cancel = true;
                }        }
      

  5.   

    public Form1()
      {
      InitializeComponent();
      this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
      }
      private void button1_Click(object sender, EventArgs e)
      {
         this.Close();
      }  private void Form1_FormClosing(object sender, FormClosingEventArgs e)
      {
      if (MessageBox.Show("是否要退出", "Application", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
      e.Cancel = true;
     
      }
      

  6.   

    public Form1()
      {
      InitializeComponent();
      this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
      }
      private void button1_Click(object sender, EventArgs e)
      {
         this.Close();
      }  private void Form1_FormClosing(object sender, FormClosingEventArgs e)
      {
      if (MessageBox.Show("是否要退出", "Application", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
      e.Cancel = true;
    else
    base.Close();
     
      }
      

  7.   

    2L正解 LZ只写了否按钮 没写是按钮
    而且还写倒了 o(︶︿︶)o 唉