I am having trouble finding out what the key differences are between the two message boxes. What is the difference between System.Windows.MessageBox
and System.Windows.Forms.MessageBox
?

- 13,750
- 36
- 127
- 202

- 1,098
- 2
- 9
- 17
-
You mention twice, in comments, that one message box "breaks your bindings" can you clarify, or have you, as suggested, started another question on that topic? – TheZenker Mar 21 '11 at 16:15
4 Answers
System.Windows.MessageBox
was added with WPF, and exists within the WPF assemblies (PresentationFramework.dll).
System.Windows.Forms.MessageBox
was added with Windows Forms, and exists within the Windows Forms assemblies.
If your program is a Windows Forms program, I would use the latter (System.Windows.Forms.MessageBox
), as it won't pull in a dependency on WPF. On the other hand, if you are developing for WPF, I'd use System.Windows.MessageBox
.

- 554,122
- 78
- 1,158
- 1,373
-
Thanks for the answer! I am using a WPF form and one of the reasons I was curious about this was when I used System.Windows.MessageBox it was causing some of my bindings to break. When I switched over to System.Windows.Forms.MessageBox my bindings were left intact. Are there certain implementation aspects of the MessageBox that may be breaking my bindings? Thanks – MisterXero Jan 11 '11 at 18:03
-
@MisterXero: No - it shouldn't have any impact at all. You might want to ask another question explaining what you're doing (with code samples) for that... – Reed Copsey Jan 11 '11 at 18:08
One additional point should be noted:
If you want to display a message box in an application that is neither a windows forms application or a forms application (such as a .NET console application), you should not drag in assembly references for either as seems to be the common mantra all over the internet.
Instead, you should use pinvoke and call into User32 as follows:
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern MessageBoxResult MessageBox(IntPtr hWnd, String text, String caption, int options);
/// <summary>
/// Flags that define appearance and behaviour of a standard message box displayed by a call to the MessageBox function.
/// </summary>
[Flags]
public enum MessageBoxOptions : uint
{
Ok = 0x000000,
OkCancel = 0x000001,
AbortRetryIgnore = 0x000002,
YesNoCancel = 0x000003,
YesNo = 0x000004,
RetryCancel = 0x000005,
CancelTryContinue = 0x000006,
IconHand = 0x000010,
IconQuestion = 0x000020,
IconExclamation = 0x000030,
IconAsterisk = 0x000040,
UserIcon = 0x000080,
IconWarning = IconExclamation,
IconError = IconHand,
IconInformation = IconAsterisk,
IconStop = IconHand,
DefButton1 = 0x000000,
DefButton2 = 0x000100,
DefButton3 = 0x000200,
DefButton4 = 0x000300,
ApplicationModal = 0x000000,
SystemModal = 0x001000,
TaskModal = 0x002000,
Help = 0x004000, //Help Button
NoFocus = 0x008000,
SetForeground = 0x010000,
DefaultDesktopOnly = 0x020000,
Topmost = 0x040000,
Right = 0x080000,
RTLReading = 0x100000,
}
/// <summary>
/// Represents possible values returned by the MessageBox function.
/// </summary>
public enum MessageBoxResult : uint
{
Ok = 1,
Cancel,
Abort,
Retry,
Ignore,
Yes,
No,
Close,
Help,
TryAgain,
Continue,
Timeout = 32000
}
var result = User32.MessageBox(IntPtr.Zero, "Debugging Break", "Your Console Application", (int)User32.MessageBoxOptions.Ok);

- 2,925
- 4
- 34
- 59

- 952
- 9
- 11
-
3JFYI: System.Windows.MessageBox from WPF Presentation Framework is just a managed wrapper around this call. WPF MessageBox is not actually a WPF window. So if you are having reservations about doing what @stacy suggests, don't have those reservations. – jrwren Sep 12 '11 at 15:58
Both eventually call the same low level windows API as far as I know...

- 32,832
- 9
- 75
- 115
-
Interesting...When I use system.windows.messagebox it breaks a binding on my WPF form but the system.windows.forms.messagebox does not. Any ideas why it might be doing that? – MisterXero Jan 11 '11 at 17:45
-
@MisterXero what exactly do you mean with "breaks a binding"? Adding an assembly reference und using the full name shouldn't break anything. Both have an internal `UnsafeNativeMethods` class in different namespaces doing about the same, although the WPF implementation is more elegant. – mbx Jun 27 '13 at 08:24
The both basically do the same thing, except system.windows.messagebox
is WPF and system.windows.forms.messagebox
is Windows Forms. If you're using WPF use the former, for WinForms use the latter.

- 6,881
- 3
- 29
- 30