我們在做桌面應用的時候經常會遇到消息提示框已彈出,但由於操作其它應用而遮擋了提示框。
解決方案:
以WPF MessageBox.Show() 為例。
1 public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button 2 , MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options) 3 { 4 return ShowCore(IntPtr.Zero, messageBoxText, caption, button, icon, defaultResult, options); 5 }
MessageBoxOptions
DefaultDesktopOnly | 131072 | 消息框顯示在交互式窗口站的默認桌面上。 指定消息框從 .NET Framework 窗口服務應用程序中顯示,以便將事件通知用戶。 |
None | 0 | 未設置選項。 |
RightAlign | 524288 | 消息框文本和標題欄標題靠右對齊。 |
RtlReading | 1048576 | 所有文本、按鈕、圖標和標題欄都從右向左顯示。 |
ServiceNotification | 2097152 | 即使用戶未登錄到計算機,消息框也會在當前活動的桌面上顯示。 指定消息框從 .NET Framework 窗口服務應用程序中顯示,以便將事件通知用戶。 |
根據參數選擇DefaultDesktopOnly和ServiceNotification都可以解決置頂的問題。