YesNo MessageBox not closing when x-button clicked

2019-02-28 20:28发布

When I open a MessageBox with options YesNo, the (usually) cancelling cross in the upper right is shown but has no effect.

System.Windows.MessageBox.Show("Really, really?", "Are you sure?", MessageBoxButton.YesNo);

If I offer YesNoCancel as options, clicking the cross closes the Dialog with DialogResult Cancel.

System.Windows.MessageBox.Show("Really, really?", "Are you sure?", MessageBoxButton.YesNoCancel);

I would have expected that the cross is "looking disabled" if not hidden at all, when clicking it has no effect. Probably I am not the first one observing this. What is your favorite way to hide/disable this button or workaround the issue?

Note: I would prefer a solution that does not use System.Windows.Forms, since I am dealing with WPF projects and would like to avoid any InterOp if possible.

3条回答
霸刀☆藐视天下
2楼-- · 2019-02-28 20:57

The Close button (in MsgBox's title bar): Since the MsgBox window is a built-in feature of the operating system, its X button is enabled only when certain buttons are present. If there is only an OK button, clicking the X button is the same as pressing OK. Otherwise, the X button is disabled unless there is a Cancel button, in which case clicking the X is the same as pressing Cancel.

http://www.autohotkey.com/docs/commands/MsgBox.htm

Its the default behavior! from the time it was MsgBox to the time its MessageBox!

查看更多
戒情不戒烟
3楼-- · 2019-02-28 21:18

Check out this CodeProject article, which outlines spinning your own MessageBox class. There's a section on disabling the close button.

查看更多
太酷不给撩
4楼-- · 2019-02-28 21:18

When you delete files in explorer (when delete confirmation is checked in recycle bin properties), a message box appears and asks "Are you sure you want to move these x items to recycle bin?" with a caption "Delete confirmation" and X at right corner. Escape also works. Buttons available are "yes" and "no" only. How can we get this done?

Either Microsoft is not following their on guidelines or not making this available for the developer.

查看更多
登录 后发表回答