在父表格前面赢取表格 [英] Win Form in front of parent form
问题描述
我有一个包含按钮的表单来创建一个新的派生类窗体。在这个按钮的回调中,我有代码
I have a form containing a button to create a new derived class form. In the callback for this button, I have the code
AnotherFormClass newForm= new AnotherFormClass();
newForm.Show();
单击按钮并运行时,newForm会立即在原始窗体前闪烁我的屏幕,但然后原来的形式回到前面。我不想用蛮力TopMost()来强制newForm始终在前面。另外,我不确定为什么我看到这种行为。任何人都可以帮忙吗?我看到有一篇文章提到了一个类似的问题 -
但是这是针对.NET 4.5和I的
When the button is clicked and this runs, the newForm momentarily flashes up in front of the original form on my screen, but then the original form comes back to the front. I don't want to use brute force TopMost() it to force newForm to always be in front. Plus, I'm not sure why I'm seeing this behaviour. Could anyone help please? I see there is an article mentioning a slightly similar problem here - Parent form is bringing to front when the menu strip of a child form is clicked but this is for .NET 4.5 and I've encountered this behaviour in 4.0 before too.
谢谢,
Chris
Thanks, Chris
推荐答案
newForm在我屏幕上的原始表单前瞬间闪现,但原始表单回到最前面。
" the newForm momentarily flashes up in front of the original form on my screen, but then the original form comes back to the front."
如果您的意思是您始终需要子表格在前面
If you mean that you always need the sub-form to be in front
请使用 Form.ShowDialog()
方法,它会将子表单保留在前面,直到关闭它为止。
use Form.ShowDialog()
method, which will keep the sub-form in front until you close it.
在你的情况中
var newForm= new AnotherFormClass();
newForm.ShowDialog(this);
详细了解 Form.ShowDialog方法
这篇关于在父表格前面赢取表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!