且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我不能把C#windows应用到前面

更新时间:2022-11-30 14:16:29

当你在表单上调用ShowDialog时,它会创建什么被称为模态对话框 - 这意味着它会覆盖应用程序中的所有现有表单,并且在新表单关闭之前它们不会响应用户输入。在此之前,您不能将任何其他表单设置为前表单,因为这是将接收键盘输入的表单。



从您显示的示例代码中,你似乎已经有了模态对话 - 他们不会;当你在它们上面调用BringToFront时,它们确实作为表格存在,因为它们必须被关闭才能在ShowDialog调用之后将控制权返回给原始代码。
When you call ShowDialog on a form, it creates what is called a Modal Dialog - which means that it overrides all existing forms in the application, and they do not respond to user input until the new form has been closed. Until then, you cannot set any other form as the "front" form because that is the one that will receive the keyboard input.

From the sample code you show, you seem to have Modal Dialogs there allready - and they dont; really exist as forms by the time you call BringToFront on them as they have to be closed in order to return control to the original code after the ShowDialog call.