VB.Net MessageBox.Show()将我的表单移到后面
时间:2020-03-06 14:57:30 来源:igfitidea点击:
我有一个MDI应用程序。当我使用MessageBox.Show()显示消息框时,当我关闭该消息框时,整个应用程序将消失在所有打开的窗口后面。
该代码没有做任何特别的事情。实际上,以下是从MDI子窗体中调用消息框的行:
MessageBox.Show(String.Format("{0} saved successfully.", Me.BusinessUnitTypeName), "Save Successful", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
Me.BusinessUnitTypeName()是一个只读属性getter,它根据成员变量的值返回一个字符串。此属性没有副作用。
有任何想法吗?
解决方案
删除" MessageBoxOptions.DefaultDesktopOnly"参数,它将正常运行。
" DefaultDesktopOnly"指定"消息框显示在活动桌面上",这将导致焦点丢失。
删除最后一个参数,MessageBoxOptions.DefaultDesktopOnly。
从MSDN:
DefaultDesktopOnly will cause the application that raised the MessageBox to lose focus. The MessageBox that is displayed will not use visual styles. For more information, see Rendering Controls with Visual Styles.
最后一个参数允许通过csrss.exe与后台Windows服务与活动桌面进行通信!有关详细信息,请参见Bart de Smet的博客文章。