如何覆盖Windows窗体中的关闭控件c# [英] How to override closing control in Windows Form c#

查看:541
本文介绍了如何覆盖Windows窗体中的关闭控件c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在form1中,我得到了:

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

然后当我点击XI时想显示前一个并隐藏当前。

解决方案

您可以覆盖

  

保护覆盖无效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
}

这篇关于如何覆盖Windows窗体中的关闭控件c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆