MessageBox

In the Microsoft.VisualBasic namespace you have the MsgBox() function
In the System.Windows.Forms namespace you have the MessageBox class.


When you have a look inside it is easy to see which method should be used to display a message box. It appears that Microsoft.VisualBasic.MsgBox() does some exception check and then passes the call onto System.Windows.Forms.MessageBox.Show() this then does pretty much the same exception checking and the passes the call onto System.Windows.Forms.SafeNativeMethods.MessageBox() which is itself a wrapper for a win32 API call to user32.dll.


You should really use System.Windows.Forms.MessageBox.
Firstly it removes an unnecessary layer of exception checking and secondly using the Microsoft.VisualBasic namespace will reduce your ability to port your application to another platform/language.



System.Windows.Forms

System.Windows.Forms.MessageBox.Show(text As String, _ 
                                  caption As String, _
                                  buttons As System.Windows.Forms.MessageBoxButtons, _
                                     icon As System.Windows.Forms.MessageBoxIcon, _
                            defaultbutton As System.Windows.Forms.MessageBoxDefaultButton, _
                                  options As System.Windows.Forms.MessageBoxOptions) _
                                          As System.Windows.Forms.DialogResult


MessageBoxButtons

AbortRetryIgnore 
OK 
OKCancel 
RetryCancel 
YesNo 
YesNoCancel 


MessageBoxIcon

AsteriskThe message box contains a symbol consisting of a lowercase letter i in a circle.
ErrorThe message box contains a symbol consisting of white X in a circle with a red background.
ExclamationThe message box contains a symbol consisting of an exclamation point in a triangle with a yellow background.
HandThe message box contains a symbol consisting of a white X in a circle with a red background.
InformationThe message box contains a symbol consisting of a lowercase letter i in a circle.
NoneThe message box contain no symbols.
QuestionThe message box contains a symbol consisting of a question mark in a circle.
StopThe message box contains a symbol consisting of white X in a circle with a red background.
WarningThe message box contains a symbol consisting of an exclamation point in a triangle with a yellow background.


MessageBoxDefaultButton

Button1 The first button on the message box is the default button.
Button2 The second button on the message box is the default button.
Button3 The third button on the message box is the default button.


MessageBoxOptions

DefaultDesktopOnlyThe message box is displayed on the active desktop. This constant is the same as ServiceNotification except that the system displays the message box only on the default desktop of the interactive window station 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.
RightAlignThe message box text is right-aligned.
RtlReadingSpecifies that the message box text is displayed with right to left reading order.
ServiceNotificationThe message box is displayed on the active desktop. The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer.


DialogResult

Abort 
Cancel 
Ignore 
No 
None 
OK 
Retry 
Yes 


Microsoft.VisualBasic

Microsoft.VisualBasic.MsgBox(prompt As Object, _ 
                          [ buttons As Microsoft.VisualBasic.MsgBoxStyle = MsgBoxStyle.OKOnly ], _
                            [ title As Object = Nothing ], _
                                    As Microsoft.VisualBasic.MsgBoxResult


MessageBoxIcon

NoneThe message box contain no symbols.
AsteriskThe message box contains a symbol consisting of a lowercase letter i in a circle.
ErrorThe message box contains a symbol consisting of white X in a circle with a red background.
ExclamationThe message box contains a symbol consisting of an exclamation point in a triangle with a yellow background.
HandThe message box contains a symbol consisting of a white X in a circle with a red background.
InformationThe message box contains a symbol consisting of a lowercase letter i in a circle.
QuestionThe message box contains a symbol consisting of a question mark in a circle.
StopThe message box contains a symbol consisting of white X in a circle with a red background.
WarningThe message box contains a symbol consisting of an exclamation point in a triangle with a yellow background.

© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

PrevNext