我有一个无国界Windows 窗体应用。
The main window creates other forms (simple dialogs where I can click yes or no) with ShowDialog()
.
Every created dialog is not visible in the taskbar, my application has only one taskbar entry that focuses my application (and if a dialog is open that one is focused). If I use ALT + TAB to cycle to all open windows I only see one entry, too.
但是,如果在我的应用程序没有焦点时创建对话框(例如,用户启动一个长时间运行的任务,开始处理其他事情,并且在后台运行),我的应用程序会显示一个对话框“任务已完成..” ."),我想返回我的申请,事情变得越来越奇怪。
- 如果我单击任务栏来聚焦我的应用程序,则主窗口将被聚焦(而不是对话框)。
- 我无法使用主窗口(因为仍然有一个打开的模式对话框)。
- Windows 7 ALT + TAB preview shows the Dialog while the taskbar mouseover preview shows the main window (in normal behavior both show the dialog in front of the main window).
- The only way to make my application usable again is to ALT + TAB to the entry and close the modal dialog.
- If I use ALT + TAB only the dialog is brought to the front and the main window is still in the background.
有办法防止这种情况发生吗?
我知道该怎么做,但大多数客户认为应用程序崩溃了,因为主窗口没有响应。
Update:
解决方案是将顶层窗口传递给ShowDialog()
方法(在大多数情况下,如果以“this”的形式使用)。
因为我不想重构我的整个代码,并且我的所有表单都继承自“MyCustomFormBase”,所以这里有一个效果很好的小解决方案。
Public Class MyCustomFormBase
Public Shared Property ApplicationMainForm() As Form
Get
Return _applicationMainform
End Get
Set(ByVal value As Form)
_applicationMainform = value
End Set
End Property
Private Shared _applicationMainform As Form
Public Shadows Function ShowDialog() As DialogResult
If MyCustomFormBase.ApplicationMainForm IsNot Nothing Then
Return MyBase.ShowDialog(MyCustomFormBase.ApplicationMainForm)
Else
Return MyBase.ShowDialog()
End If
End Function
Public Shadows Function ShowDialog(ByVal owner As IWin32Window) As DialogResult
Return MyBase.ShowDialog(owner)
End Function
End Class
在我使用的主窗口的构造函数中
MyCustomFormBase.ApplicationMainForm = Me
一次。它帮助我重构了半天;)
您是否尝试过将对主窗口的引用传递给ShowDialog
calls?
// assuming this code is in the main form (so "this" refers to the main form)
DialogForm dialog = new DialogForm();
DialogResult result = dialog.ShowDialog(this);
引用自此超载的文档:
此版本的 ShowDialog 方法
允许您指定特定的表单
或将拥有该对话框的控件
显示的框。如果您使用
此方法的版本没有
参数,显示对话框
将自动归
您当前活动的窗口
应用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)