我如何知道封闭式表格的方式? [英] How can I know the way of a closed form class?

查看:269
本文介绍了我如何知道封闭式表格的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种形式,在form1,我这样形式化form2 ..



  dim  form2  as   new  form2 





我可以使用showdialog来使用



 panel.ShowDialog()
panel.DataGridView1 ....< codes>







在form2中。有一个关闭按钮和按钮点击事件是这样的..



<前lang =vb>关闭()





我想知道如何通过点击x按钮或关闭按钮来了解form2类是什么?



plz给我建议



我尝试过:



< pre lang =vb> close()

解决方案

基本上,CloseReason属性为FormClosingEventArgs不会给你任何有用的东西 - 它为你的X按钮和调用Close方法的代码提供了UserClosing。



所以添加一个表单的属性,使其成为布尔值,并在构造函数中将其设置为False。在您的按钮处理程序中,在调用Close之前将其设置为True。

然后处理FormClosing事件,并使用sender参数来标识表单实例。检查属性,如果是,则用户关闭表单是你的按钮。


I Have two forms and at form1, I inicialize form2 like this..

dim form2 as new form2



and i can use it using showdialog

        panel.ShowDialog()
panel.DataGridView1....<codes>




In form2. There is a close button and button click event is like this..

close()



Thing I'd like know is how i can know form2 class is closed by clicking x button or close button?

plz give me advice

What I have tried:

<pre lang="vb">close()

解决方案

Basically, the CloseReason property of the FormClosingEventArgs won't give you anything useful - it gives you "UserClosing" for the "X" button and from the code calling the Close method.

So add a property to the form, make it a Boolean, and set it False in the constructor. In you button handler, set it True before calling Close.
Then handle the FormClosing event, and use the sender parameter to identify the form instance. Check the property, and if it's true, it was your button the user closed the form with.


这篇关于我如何知道封闭式表格的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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