Windows窗体中的表单结束事件? [英] Form Closing Event in Windows Form?

查看:99
本文介绍了Windows窗体中的表单结束事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Public Class1()
{
   this.FormClosing += OnFormClosing();
}

private void OnFormClosing(object Sender, EventArgs e)
{
   base.OnFormClosing(e);
   if (e.CloseReason == CloseReason.WindowsShutDown)
   {
      form_closing();//here i wrote my function to happen
   }
}

private void formcloasing()
{
   Class cls = new cls();
   cls.RemovefromOpenedChats((int)this.Tag);
}



我面临的问题:

方法'OnFormClosing'没有重载需要0个参数



我需要的解决方案?

如何在点击红色关闭(X)按钮时以Windows窗体编写函数?


Issue which I am facing:
No overload for method 'OnFormClosing' takes 0 arguments

Solution I need?
How to write a function in windows form while clicking red close(X) button?

推荐答案

试试这个:

Try this:
 protected override void OnFormClosing(FormClosingEventArgs e)
{
    //base.OnFormClosing(e);
    if (e.CloseReason == CloseReason.WindowsShutDown)
    { 
        //Do your stuff here
    }
}









--Amit





--Amit


这是您从私有虚空OnFormClosin调用的方法g(object Sender,EventArgs e)

This is the method you are making call from private void OnFormClosing(object Sender, EventArgs e)
private void formcloasing()
{
Class cls = new cls();
cls.RemovefromOpenedChats((int)this.Tag);
}





..你传递参数



..and you're passing a parameter

base.OnFormClosing(e);



哪个完全无效。


Which is completely invalid.


Public Constructor_Class( )

{

this.FormClosing + = OnFormClosing();

}

public void OnForm_Closing(object Sender, EventArgs e)

{

//你的功能;

}
Public Constructor_Class()
{
this.FormClosing+=OnFormClosing();
}
public void OnForm_Closing(object Sender,EventArgs e)
{
//your function;
}


这篇关于Windows窗体中的表单结束事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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