表格关闭事件 [英] Form Close Event

查看:105
本文介绍了表格关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人;
我的应用程序变得很奇怪...
在创建表格边框样式=无之前,我创建了自己的关闭按钮,该按钮将关闭当前窗口并打开并将值传递给其他表格.并正在完美地工作..例如,如果我有form1,我想将其关闭并打开form2,完成后,我想在关闭form2之后再次打开form1 ...

我的代码是这样的:

Dear All ;
My application is going strange ...
before I was making the form border style = none then I create my own close button which will close the curent window and open and pass values to other form. and was working prefectly.. for example if I have form1 and I want to close it and open form2 and after finishing I want to open again form1 after closing form2...

My code was like that :

openform2(object sender, EventArgs e)
    {
        functions fn = new functions();
        form2 ts = new form2();
        ts.Text = " Welcome Mr." + fn.GetuserNameFromFile();
        this.Hide();

        ts.ShowDialog();
        this.Close();
    }

然后我打开form2,依此类推...


之后,我使formborderstyle = sizable,然后我想在不使用我自己的按钮的情况下捕获表单关闭事件. 在初始化函数中,我添加了以下行:

then I opens form2 and so on...


after that I make the formborderstyle = sizable then I want to catch the form close event without using my own button .. what I have done in the form2 is the following :
at the intialize function I have added this line :

this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);



然后我插入函数:



and then I carete the function :

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        functions fn = new functions();
        form1 f1 = new form1();
        f1.Text = " Welcome Mr." + fn.GetuserNameFromFile();
      // that means to close the current form2 and show form1 again 
        this.Hide();
        f1.ShowDialog();
        
        this.Close();
        this.Dispose();
    }




所以现在form2成功关闭了,但是当我在完成过程后尝试关闭form1时,我单击关闭按钮将其隐藏,然后将其隐藏并显示...因此它没有关闭...

如何终止该过程,我想关闭该软件...

帮助...
问候..




so what happens now the form2 closed succesfully , but when I try to close the form1 after finishing my proccess so I click on close button it is hiding it and then showing it hidding and showing ... so it is not closing ...

how to kill the proccess I want to close the software...

help...
regards..

推荐答案

您正在执行FormClosing事件中的this.Close().考虑到表单已经在尝试关闭,这很奇怪.

替换为:
You are doing this.Close() in the FormClosing event. That is pretty strange considering that the form is already trying to close.

Replace this:
this.Close();
this.Dispose();



有了这个



With this

e.Cancel = false;



祝你好运!



Good luck!




删除

Hi ,

Remove

this.
Close();
        this.Dispose();



形成您的代码.在执行此行格式时,将发生关闭事件.



Form your code. On execution of this line form closing event occur.


这篇关于表格关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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