从一个窗口捕获事件到另一个窗口 [英] capturing an event from one window to another

查看:136
本文介绍了从一个窗口捕获事件到另一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从主机控制第二个窗口显示.在一个窗口的复选框中,我将调用show()或hide方法().我捕获第二个窗口的关闭方法以防止其关闭,以便将窗口2保留在内存中.如何使用窗口2中的close方法的事件导致未选中窗口1中的复选框?

顺便说一句,这是使用WPF

谢谢

I want to control a second window display from a main. In a checkbox from window one I call either a show() or hide method(). I trap the closing method of the second window to prevent it from closing so as to keep the window 2 in memory. How can I use the event of the closing method from window 2 to cause the checkbox from window one to be unchecked?

BTW, this is using WPF

Thanks

推荐答案

您可以简单地定义一个委托并将自己的事件添加到form2.然后,form1可以设置该事件处理程序以捕获事件.

以下是有关代表和事件的一些链接:

C#中的事件和事件处理 [ http://msdn.microsoft.com/en-us/library/aa645739% 28VS.71%29.aspx [ ^ ]

您可能还会滥用form2.OnClosed(.net 1.1)或form2.OnFormClosed(.net 2.0 up)事件,然后向该事件添加一个form1方法来捕获它.

祝你好运!
You can simply define a delegate and add your own event to form2. form1 can then set that event handler to capture the event.

Here some links on delegates and events:

Events and event handling in C#[^]

http://msdn.microsoft.com/en-us/library/aa645739%28VS.71%29.aspx[^]

You could probably also abuse the form2.OnClosed (.net 1.1) or form2.OnFormClosed (.net 2.0 up) event and add a method of form1 to that event to capture it.

Good luck!


这篇关于从一个窗口捕获事件到另一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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