简体   繁体   English

如何临时阻止表单获得焦点/激活?

[英]How can I temporarily prevent a form from getting focus/activating?

my application opens n forms and the user can freely switch back and forth among these forms. 我的应用程序打开了n个表单,用户可以在这些表单之间自由地来回切换。 When the user decides to confirm the operations performed on one of the forms, I would like to block the other ones until this process (which can potentially open MessageBoxes and/or other forms) comes to an end. 当用户决定确认对其中一种表单执行的操作时,我想阻止其他表单,直到该过程(可能会打开MessageBoxes和/或其他表单)结束。 It is not enough to disable the forms, since the user can't do anything on them, but the Activated event is fired, and this is exactly what I want to avoid. 禁用表单是不够的,因为用户无法对表单执行任何操作,但是激发了Activated事件,这正是我要避免的事情。 I tried to set ControlStyles.Selectable to false to all these forms, but it doesn't work. 我尝试将所有这些形式的ControlStyles.Selectable设置为false,但是它不起作用。

Just in order to make it clearer, the forms cover the whole screen, so the users activate them clicking on the taskbar. 只是为了使其更清晰,表单覆盖了整个屏幕,因此用户可以单击任务栏上的来激活它们。 This is the situation where opening a modal form and having the confirm code executed there does not prevent the Activated event to be fired. 在这种情况下,打开模式窗体并在其中执行确认代码不会阻止激发事件被触发。

尝试使用Form.ShowDialog()方法。

You can use Form.ShowDialog Method method to display a modal dialog box in your application. 您可以使用Form.ShowDialog方法方法在您的应用程序中显示模式对话框。 When this method is called, the code following it is not executed until after the dialog box is closed. 调用此方法时,直到关闭对话框后,该代码之后的代码才会执行​​。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM