表格隐藏在背景中 [英] Form hiding in background
问题描述
我正在VB.net 2008中的一个项目上工作.从无模态表单中以模态形式打开表单时出现问题.我已经附加了一个项目来演示该问题.该演示包含具有以下特征的三种形式.
-"Form1"是演示应用程序的主要形式,
-通过"Form1"将"Form2"作为无模式表单打开.它是隐藏的(使用me.hide()方法),而不是关闭,并且在"Form2"的关闭事件中取消关闭.
-通过"Form2"打开"Form3"作为模态形式.
现在的问题是,当我关闭"Form3"后隐藏"Form2"时,"Form1"也隐藏在后台(当其他一些窗口也打开时,即Windows资源管理器).我无法找到此行为的原因.这看起来像是一个常见问题,并且必须由其他人遇到,但是我无法在Internet上找到它.因此,请帮忙,因为我需要此问题的原因和解决方案.
问候,
Hassan
Hi,
I am working on a project in VB.net 2008. I have a problem arising while opening a form as modal from a modeless form. I have attached a project to demonstrate the problem. This demonstration contains three forms with following characteristics.
- "Form1" is main form of the demo application and
- "Form2" is opened as modeless form through "Form1". It is hidden (using me.hide() method) instead of closing and Cancel the closing in closing event of "Form2".
- "Form3" is opened as modal form through "Form2".
Now problem is when I hide "Form2" after closing "Form3", "Form1" also hides in the background (when some other windows are also open i.e. Windows explorer). I am unable to find a reason for this behavior. This should looks like a common problem and must be encountered by someone else but I am unable to find it on internet. So please help as I need reason and solution for this problem.
Regards,
Hassan
推荐答案
在隐藏form2之前插入此代码:
Owner.Focus()
这将为所有者(表单1)提供焦点,并且在隐藏表单2时可能会更改此行为.
Insert this before hiding form2:
Owner.Focus()
This will give the owner (form 1) the focus and may change this behavior when form 2 is hidden.
这篇关于表格隐藏在背景中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!