且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何覆盖Windows窗体中的关闭控件c#

更新时间:2023-12-06 07:55:04

您可以覆盖

   保护覆盖无效OnFormClosing(FormClosingEventArgs e)
{
if(e.CloseReason == CloseReason.WindowsShutDown)return;

//在此处进行
}


I would like to make X control closing window to hide current display previous form.

In form1 I got:

private void button1_Click(object sender, EventArgs e)
{
    Form2 form2 = new Form2();
    form2.Tag = this;
    form2.Show(this);
    Hide();
}

and then when I click X I would like to show previous and hide the current.

You can override OnFormClosing to do this.

 protected override void OnFormClosing(FormClosingEventArgs e)
{
    if (e.CloseReason == CloseReason.WindowsShutDown) return;

    // DO WHATEVER HERE
}