[Reprint] MessageBox. Show usage in C # And MsgBox usage in VB. NET,
1. Use MessageBox. Show in C #
MessageBox. Show (String) displays message boxes with specified text. Supported by. NET Compact Framework.
MessageBox. Show (IWin32Window, String) displays a message box with the specified text before the specified object.
MessageBox. Show (String, String) displays message boxes with the specified text and title. Supported by. NET Compact Framework.
MessageBox. Show (IWin32Window, String, String) displays a message box with the specified text and title before the specified object.
MessageBox. Show (String, String, MessageBoxButtons) displays message boxes with the specified text, title, and button.
MessageBox. Show (IWin32Window, String, String, MessageBoxButtons) displays a message box with the specified text, title, and button before the specified object.
MessageBox. Show (String, String, MessageBoxButtons, MessageBoxIcon) displays message boxes with specified text, title, buttons, and icons.
MessageBox. Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon) displays a message box with the specified text, title, buttons, and icons before the specified object.
MessageBox. Show (String, String, MessageBoxButtons, MessageBoxIcon, and MessageBoxDefaultButton) displays a message box with the specified text, title, button, icon, and default button. Supported by. NET Compact Framework.
MessageBox. Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton) displays a message box with the specified text, title, button, icon, and default button before the specified object.
MessageBox. Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions) displays message boxes with specified text, title, buttons, icons, default buttons, and options.
MessageBox. show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions) displays a message box with the specified text, title, button, icon, default button, and options before the specified object.
MessageBox. show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, Boolean) displays a message box with the specified text, title, button, icon, default button, option, and help button.
MessageBox. show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String) use a specified help file to display a message box with the specified text, title, button, icon, default button, options, and "help" button.
MessageBox. show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String) use a specified help file to display a message box with the specified text, title, button, icon, default button, options, and "help" button.
MessageBox. show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator) use the specified help file and HelpNavigator to display a message box with the specified text, title, button, icon, default button, option, and "help" button.
MessageBox. show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String) use the specified help file and help keyword [guan jian zi] to display a message box with the specified text, title, button, icon, default button, options, and "help" button.
MessageBox. show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator) use the specified help file and HelpNavigator to display a message box with the specified text, title, button, icon, default button, option, and "help" button.
MessageBox. show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String) use the specified help file and help keyword [guan jian zi] to display a message box with the specified text, title, button, icon, default button, options, and "help" button.
MessageBox. show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object) use the specified help file, HelpNavigator, and help topic to display a message box with the specified text, title, button, icon, default button, options, and "help" button.
MessageBox. show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object) use the specified help file, HelpNavigator, and help topic to display a message box with the specified text, title, button, icon, default button, options, and "help" button.
Usage example:
DialogResult ret = MessageBox. Show ("are you sure you want to delete the [shan chu] record? "," Delete [shan chu] ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question );
MessageBox. Show ("Message [ti shi] ", "Message Title", MessageBoxButtons. OK );
MessageBox. Show ("[ti shi] ", "", MessageBoxButtons. OK, MessageBoxIcon. Error );
MessageBox is often used in programs.
MessageBox. Show () contains a total of 21 [zhong zai] methods. The common usage is summarized as follows:
1. MessageBox. Show ("Hello ~~~~ ");
The simplest one is to display only the prompt [ti shi.
2. MessageBox. Show ("There are something wrong! "," ERROR ");
You can add the question [shang biao] to the message box.
3. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel) = DialogResult. OK)
{
// Delete
}
This is used when you ask whether to delete [shan chu.
4. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question) = DialogResult. OK)
{
// Delete
}
You can add an Icon to MessageBox. net provides a common Icon Selection [xuan ze].
5. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question, MessageBoxDefaultButton. Button2) = DialogResult. OK)
{
// Delete
}
The default focus of MessageBox can be changed as follows:
6. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question, MessageBoxDefaultButton. Button2, MessageBoxOptions. RtlReading) = DialogResult. OK)
{
// Delete
}
Reverse display:
7. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question, MessageBoxDefaultButton. Button2, MessageBoxOptions. RightAlign, true) = DialogResult. OK)
{
// Delete
}
Add the Help button:
8. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question, queue. Button1, MessageBoxOptions. RtlReading, @"/folder/file.htm ") = DialogResult. OK)
{
// Delete
}
Specify the path of the Help File [lu jing] and click it to open the Help file under [lu jing.
9. // HelpNavigator specifies a constant to indicate the Help File element to be displayed in [zhi shi. The Find help file is displayed on the [sou suo] Page.
If (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. question, MessageBoxDefaultButton. button1, MessageBoxOptions. rtlReading, @ "/folder/file.htm", HelpNavigator. find) = DialogResult. OK)
{
// Delete
}
There are also some usage, which will not be described here. If you are interested, refer to the MessageBox class of MSDN.
Ii. MsgBox usage in VB. NET
MsgBox: Prompts a dialog box that displays a message.
Examples:
MsgBox ("Thank You for the Help!") |
Information from the MSDN:MsgBox Function
Parameters
-
Prompt
-
Required.
StringExpression displayed as the message in the dialog box. The maximum length
PromptIs approximately 1024 characters, depending on the width of the characters used. If
PromptConsists of more than one line, you can separate the lines using a carriage return character (
Chr (13
)), A linefeed character (
Chr (10
)), Or a carriage return/linefeed character combination (
Chr (13
)&
Chr (10
)) Between each line.
-
Buttons
-
Optional. numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. if you omit
Buttons, The default value is zero.
-
Title
-
Optional.
StringExpression displayed in the title bar of the dialog box. If you omit
Title, The application name is placed in the title bar.
Settings
TheMsgBoxStyleEnumeration values are listed in the following table.
Enumeration |
Value |
Description |
OKOnly |
0 |
Displays OK button only. |
OKCancel |
1 |
Displays OK and Cancel buttons. |
AbortRetryIgnore |
2 |
Displays Abort, Retry, and Ignore buttons. |
YesNoCancel |
3 |
Displays Yes, No, and Cancel buttons. |
YesNo |
4 |
Displays Yes and No buttons. |
RetryCancel |
5 |
Displays Retry and Cancel buttons. |
Critical |
16 |
Displays Critical Message icon. |
Question |
32 |
Displays Warning Query icon. |
Exclamation |
48 |
Displays Warning Message icon. |
Information |
64 |
Displays Information Message icon. |
DefaultButton1 |
0 |
First button is default. |
DefaultButton2 |
256 |
Second button is default. |
DefaultButton3 |
512 |
Third button is default. |
ApplicationModal |
0 |
Application is modal. The user must respond to the message box before continuing work in the current application. |
SystemModal |
4096 |
System is modal. All applications are suincluded until the user responds to the message box. |
MsgBoxSetForeground |
65536 |
Specifies the message box window as the foreground window. |
MsgBoxRight |
524288 |
Text is right-aligned. |
MsgBoxRtlReading |
1048576 |
Specifies text shoshould appear as right-to-left reading on Hebrew and Arabic systems. |
The first group of values (0-5) describes the number and type of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0,256,512) determines which button is the default; the fourth group (0, 4096) determines the modality of the message box, and the specified TH group specifies whether or not the message box window is the foreground window, along with the alignment and direction of the text. when adding numbers to create a final value forButtonsArgument, use only one number from each group.
Return Values
Constant |
Value |
OK |
1 |
Cancel |
2 |
Abort |
3 |
Retry |
4 |
Ignore |
5 |
Yes |
6 |
No |
7 |
Exceptions/Errors
Exception type |
Error number |
Condition |
ArgumentException |
5 |
PromptIs notStringExpression, orTitleIs invalid. |
InvalidOperationException |
5 |
Process is not running in User Interactive mode. |
InvalidEnumArgumentException |
5 |
One or more parameters not a memberMsgBoxResultOrMsgBoxStyleEnumerations. |
Remarks
If the dialog box displaysCancelButton, pressing the ESC key has the same effect as clickingCancel. If the dialog box containsHelpButton, context-sensitive Help is provided for the dialog box. However, no value is returned until one of the other buttons is clicked.
NoteTo specify more than the first argument, you must use
MsgBoxFunction in an expression. If you omit any positional arguments, you must retain the corresponding comma delimiter.Example
This example usesMsgBoxFunction to display a critical-error message in a dialog box with Yes and No buttons. The No button is specified as the default response. This is done by combiningMsgBoxConstant values into one numeric expression. in this case, adding 4 (the Yes/No button combination) and 16 (the Critical Message window) and 256 (the second button as default button) gives a total of 276. the value returned byMsgBoxFunction depends on the button chosen by the user: Yes returns a value of 6; No returns a value of 7.
Dim msg As StringDim title As StringDim style As MsgBoxStyleDim response As MsgBoxResultmsg = "Do you want to continue?" ' Define message.style = MsgBoxStyle.DefaultButton2 Or _ MsgBoxStyle.Critical Or MsgBoxStyle.YesNotitle = "MsgBox Demonstration" ' Define title.' Display message.response = MsgBox(
msg, style, title)
' or MsgBox(msg, MsgBoxStyle.YesNo, title)If response = MsgBoxResult.Yes Then ' User chose Yes. ' Perform some action.Else ' Perform some other action.End If
Source
Link ①: http://blog.csdn.net/fan158/article/details/5891780
Link ②: http://www.lob.cn/jq/kfjq/570.shtml