诱捕表格结束事件 [英] Trapping the Form Closing Event

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

问题描述

我有一个.NET 2.0 MDI应用程序,其中子表单有一个Tab

控件。选项卡控件中的每个选项卡都有一个验证事件,以便

处理用户更改选项卡时应该执行的操作。


但这些验证事件也是当子窗体

或主(父)窗体关闭图标被单击时触发。我需要这些

事件才能知道他们是否被调用,因为app(或孩子

窗口)正在关闭。我已经在'

FormClosing事件的形式中设置了一个布尔值,但似乎Validating事件在FormClosing事件之前触发了

! ARGGHHHH !!!


我如何在Tab Validating事件中告知由于

表格或应用被关闭而被解雇?

解决方案

我认为在

上调用了Validate方法TabChange事件和FormClosing活动?


如果是这样,为什么不在Validate方法中包含一个ByVal,比如

isClosing作为布尔值


所以在表单关闭时它将是


sub FormClosing

ValidateTabs(True)

end sub


并在标签中更改


sub TabChanged

ValidateTabs(false)

end sub

然后在validateTabs子中你只需要一个if语句来检查

isclosing的值,以查看它是否在表单被调用时被调用

结束。


对不起,如果我这里有完全错误的结尾




我不相信你能。相反,你必须考虑改变你想要做的事情的

逻辑。

问题是在验证发生后调用关闭是因为

当控件(比如文本框)失去焦点时,会发生验证。

失去焦点发生在sys_cmd之前或任何其他关闭

应用程序的方式发生而不是你自己的代码强制它关闭。你可能

能够捕捉失去的焦点,看看有什么焦点并确定

用户是否按下关闭按钮,但我不认为你'如果他们有运气,那么就有运气。
点击图标调出系统菜单。总而言之,我会说

答案是否定的,你会更好地看一下不同的程序逻辑。


问候,


比尔。


< za *** @ construction-imaging.comwrote in message

news:11 ********************* @ q75g2000hsh.googlegro ups.com ...


>我有一个.NET 2.0 MDI应用程序,其中子表单有一个Tab

控件。选项卡控件中的每个选项卡都有一个验证事件,以便

处理用户更改选项卡时应该执行的操作。


但这些验证事件也是当子窗体

或主(父)窗体关闭图标被单击时触发。我需要这些

事件才能知道他们是否被调用,因为app(或孩子

窗口)正在关闭。我已经在'

FormClosing事件的形式中设置了一个布尔值,但似乎Validating事件在FormClosing事件之前触发了

! ARGGHHHH !!!


我如何在Tab Validating事件中告知由于

表格或应用被关闭而被解雇?


8月8日上午11:33,andrew.a ... @ thenbs.com写道:


我是否认为在TabChange事件和FormClosing事件上调用了Validate方法




如果是这样,为什么不呢?在Validate方法中包含一个ByVal类似于

isClosing作为布尔值


所以在表单关闭时它将是


sub FormClosing

ValidateTabs(True)

end sub


并在标签中更改

sub TabChanged

ValidateTabs(false)

end sub


然后在validateTabs子中你只需要一个如果声明要检查

isclosing的值,看看它是否在表格结束时被调用

结束。


对不起,如果一世这里有完全错误的结尾



感谢您的回复。我没有在表单关闭事件中手动调用选项卡验证

事件,它会自动被触发。我是

在表单结束事件中在子表单中设置一个布尔值,因此

验证事件可以知道因为表格而被解雇

结束,但由于验证事件代码在表格

结束事件之前运行,设置该布尔值是没用的。这是我的

问题。


I have a .NET 2.0 MDI application where the child form has a Tab
Control. Each of the Tab in the Tab Control has a Validating event to
handle what it should do when the user changes tabs.

But these Validating Events are also fired when either the child form
or the main (parent) form Close icon is clicked. And I need for these
events to know if they are being invoked because the app (or child
window) is being closed. I have set a boolean in BOTH of the form''s
FormClosing event, but it seems that the Validating event is firing
BEFORE the FormClosing event!!! ARGGGHHHH!!!

How can I tell in a Tab Validating event that it is being fired due to
the form or app being closed?

解决方案

Am i right in thinking that the Validate method is being called on
both the TabChange event and the FormClosing event?

If so, why not include a ByVal in the Validate method something like
isClosing as a boolean

so in form closing it would be

sub FormClosing
ValidateTabs(True)
end sub

and in the tab changed

sub TabChanged
ValidateTabs(false)
end sub
then in the validateTabs sub you just need an if statement to check
the value of isclosing to see if it was called when the form was
closing.

Sorry if I have the totally wrong end of the stick here


Hi,

I don''t believe you can. Instead you''ll have to think about changing the
logic of what you are trying to do.
The problem is the closing is invoked after the validation occurs because
the validation occurs when the control, say a textbox, looses focus. That
lost focus occurs before the sys_cmd or any other way of closing the
application occurs other than your own code to force it to close. You might
be able to trap the lost focus, and see what gets focus and determine if the
user pressed the close button, but I don''t think you''d have any luck if they
bring up the system menu by clicking on the icon. So all in all, I''d say
the answer is no, you''d be better off looking at a different program logic .

Regards,

Bill.


<za***@construction-imaging.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...

>I have a .NET 2.0 MDI application where the child form has a Tab
Control. Each of the Tab in the Tab Control has a Validating event to
handle what it should do when the user changes tabs.

But these Validating Events are also fired when either the child form
or the main (parent) form Close icon is clicked. And I need for these
events to know if they are being invoked because the app (or child
window) is being closed. I have set a boolean in BOTH of the form''s
FormClosing event, but it seems that the Validating event is firing
BEFORE the FormClosing event!!! ARGGGHHHH!!!

How can I tell in a Tab Validating event that it is being fired due to
the form or app being closed?


On Aug 8, 11:33 am, andrew.a...@thenbs.com wrote:

Am i right in thinking that the Validate method is being called on
both the TabChange event and the FormClosing event?

If so, why not include a ByVal in the Validate method something like
isClosing as a boolean

so in form closing it would be

sub FormClosing
ValidateTabs(True)
end sub

and in the tab changed

sub TabChanged
ValidateTabs(false)
end sub

then in the validateTabs sub you just need an if statement to check
the value of isclosing to see if it was called when the form was
closing.

Sorry if I have the totally wrong end of the stick here

Thanks for your reply. I am not manually calling the tab validating
event in the form closing event, it is automatically being fired. I am
setting a boolean in the child form in the form closing event so the
validating event can know that is was fired because of the form
closing, but since the validating event code runs BEFORE the form
closing event, setting that boolean there is useless. That is my
problem.


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

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