[转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一、C#中MessageBox.Show用法
MessageBox.Show (String) 显示具有指定文本的消息框。 由 .NET Compact Framework 支持。
MessageBox.Show (IWin32Window, String) 在指定对象的前面显示具有指定文本的消息框。
MessageBox.Show (String, String) 显示具有指定文本和标题的消息框。由 .NET Compact Framework 支持。
MessageBox.Show (IWin32Window, String, String) 在指定对象的前面显示具有指定文本和标题的消息框。
MessageBox.Show (String, String, MessageBoxButtons) 显示具有指定文本、标题和按钮的消息框。
MessageBox.Show (IWin32Window, String, String, MessageBoxButtons) 在指定对象的前面显示具有指定文本、标题和按钮的消息框。
MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon) 显示具有指定文本、标题、按钮和图标的消息框。
MessageBox.Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon) 在指定对象的前面显示具有指定文本、标题、按钮和图标的消息框。
MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton) 显示具有指定文本、标题、按钮、图标和默认按钮的消息框。 由 .NET Compact Framework 支持。
MessageBox.Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton) 在指定对象的前面显示具有指定文本、标题、按钮、图标和默认按钮的消息框。
MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions) 显示具有指定文本、标题、按钮、图标、默认按钮和选项的消息框。
MessageBox.Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions) 在指定对象的前面显示具有指定文本、标题、按钮、图标、默认按钮和选项的消息框。
MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, Boolean) 显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String) 使用指定的帮助文件显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
MessageBox.Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String) 使用指定的帮助文件显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator) 使用指定的帮助文件和 HelpNavigator 显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String) 使用指定的帮助文件和帮助关键字[guan jian zi]显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
MessageBox.Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator) 使用指定的帮助文件和 HelpNavigator 显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
MessageBox.Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String) 使用指定的帮助文件和帮助关键字[guan jian zi]显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object) 使用指定的帮助文件、HelpNavigator 和帮助主题显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
MessageBox.Show (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object) 使用指定的帮助文件、HelpNavigator 和帮助主题显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和"帮助"按钮的消息框。
用法如:
DialogResult ret =MessageBox.Show( "确定要删除[shan chu]记录么?" , "删除[shan chu]", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
MessageBox.Show( "提示[ti shi]信息", " 信息标题", MessageBoxButtons.OK);
MessageBox.Show( "提示[ti shi]信息", " 信息标题", MessageBoxButtons.OK, MessageBoxIcon.Error);
我们在程序中经常会用到MessageBox。
MessageBox.Show()共有21中重载[zhong zai]方法。现将其常见用法总结如下:
1. MessageBox .Show( "Hello~~~~" );
最简单的,只显示提示[ti shi]信息。

2. MessageBox .Show( "There are something wrong!" , "ERROR" );
可以给消息框加上标[shang biao]题。

3. if ( MessageBox .Show( "Delete this user?" , "Confirm Message" , MessageBoxButtons .OKCancel) == DialogResult .OK)
{
//delete
}
询问是否删除[shan chu]时会用到这个。

4. if ( MessageBox .Show( "Delete this user?" , "Confirm Message" , MessageBoxButtons .OKCancel, MessageBoxIcon .Question) == DialogResult .OK)
{
//delete
}
可以给MessageBox加上一个Icon,.net提供常见的Icon共选择[xuan ze]。

5. if ( MessageBox .Show( "Delete this user?" , "Confirm Message" , MessageBoxButtons .OKCancel, MessageBoxIcon .Question, MessageBoxDefaultButton .Button2) == DialogResult .OK)
{
//delete
}
可以改变MessageBox的默认焦点,如下:

6. if ( MessageBox .Show( "Delete this user?" , "Confirm Message" , MessageBoxButtons .OKCancel, MessageBoxIcon .Question, MessageBoxDefaultButton .Button2, MessageBoxOptions .RtlReading) == DialogResult .OK)
{
//delete
}
反向显示:

7. if ( MessageBox .Show( "Delete this user?" , "Confirm Message" , MessageBoxButtons .OKCancel, MessageBoxIcon .Question, MessageBoxDefaultButton .Button2, MessageBoxOptions .RightAlign, true ) == DialogResult .OK)
{
//delete
}
添加Help按钮:

8. if ( MessageBox .Show( "Delete this user?" , "Confirm Message" , MessageBoxButtons .OKCancel, MessageBoxIcon .Question, MessageBoxDefaultButton .Button1, MessageBoxOptions .RtlReading, @"/folder/file.htm" ) == DialogResult .OK)
{
//delete
}
指定帮助文件的路径[lu jing],点击即可打开该路径[lu jing]下的帮助文件。

9. //HelpNavigator 指定常数来指示[zhi shi]要显示的帮助文件元素。 Find 帮助文件将打开到搜索[sou suo]页。
if ( MessageBox .Show( "Delete this user?" , "Confirm Message" , MessageBoxButtons .OKCancel, MessageBoxIcon .Question, MessageBoxDefaultButton .Button1, MessageBoxOptions .RtlReading, @"/folder/file.htm" , HelpNavigator .Find) == DialogResult .OK)
{
//delete
}

还有一些用法,不是太实用这里就不一一介绍了,有兴趣的朋友可以参考下这里: MSDN 的MessageBox类。
二、VB.NET中MsgBox用法
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. String expression displayed as the message in the dialog box. The maximum length of Prompt is approximately 1024 characters, depending on the width of the characters used. If Prompt consists 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. String expression displayed in the title bar of the dialog box. If you omit Title, the application name is placed in the title bar.
Settings
The MsgBoxStyle enumeration 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 suspended 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 should 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 fifth 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 for the Buttons argument, 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
|
Prompt is not a String expression, or Titleis invalid. |
|
InvalidOperationException
|
5
|
Process is not running in User Interactive mode. |
|
InvalidEnumArgumentException
|
5
|
One or more parameters not a member ofMsgBoxResult or MsgBoxStyleenumerations. |
Remarks
If the dialog box displays a Cancel button, pressing the ESC key has the same effect as clicking Cancel. If the dialog box contains a Help button, context-sensitive Help is provided for the dialog box. However, no value is returned until one of the other buttons is clicked.
Note To specify more than the first argument, you must use the MsgBox function in an expression. If you omit any positional arguments, you must retain the corresponding comma delimiter.
Example
This example uses the MsgBox function 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 combining the MsgBox constant 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 by the MsgBox function depends on the button chosen by the user: Yes returns a value of 6; No returns a value of 7.
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Do you want to continue?" ' Define message.
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "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
原文出处
链接①:http://blog.csdn.net/fan158/article/details/5891780
链接②:http://www.lob.cn/jq/kfjq/570.shtml
[转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法的更多相关文章
- VB6中的引用传递 与 VB.NET中的引用传递的区别
首先注意一点,在VB6中缺省参数传递的方式是:引用传递,而在VB.NET中缺省参数传递的方式是:值传递. 然后我们看下面VB6中的引用传递与VB.NET中的引用传递的对比. VB6中的引用传递 Pri ...
- 【转】VC中MessageBox与AfxMessageBox用法与区别
原文网址:http://blog.csdn.net/holybin/article/details/28403109 一.MessageBox()用法 1.函数原型 Messagebox函数在Win3 ...
- VC中MessageBox与AfxMessageBox用法与区别
一.MessageBox()用法 1.函数原型 Messagebox函数在Win32 API和MFC里的定义有区别. Win32 API的定义如下: int WINAPI MessageBox( ...
- 转:VC中MessageBox的常见用法
一.关于MessageBox 消息框是个很常用的控件,属性比较多,本文列出了它的一些常用方法,及指出了它的一些应用场合. 1.MessageBox("这是一个最简单的 ...
- VC中MessageBox的常见用法
一.关于MessageBox 消息框是个很常用的控件,属性比较多,本文列出了它的一些常用方法,及指出了它的一些应用场合. 1.MessageBox("这是一个最简单的 ...
- C++Builder中MessageBox的基本用法
C++Builder中MessageBox的基本用法 返回值:IDYES=Application->MessageBox("","",MBYESNO) i ...
- C#中MessageBox用法大全(转)
我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~&quo ...
- VC++中MessageBox的常见用法详解
消息框是个很常用的控件,属性比较多,本文列出了它的一些常用方法,及指出了它的一些应用场合. 1.MessageBox("这是一个最简单的消息框!"); ...
- Delphi中MessageBox用法
消息框是个很常用的控件,属性比较多,本文列出了它的一些常用方法,及指出了它的一些应用场合. 1.最简单用法,不带图形 MessageBox(0,'不同意','提示',MB_OK); MessageBo ...
随机推荐
- 【.net 深呼吸】细说CodeDom(8):分支与循环
有人会问,为啥 CodeDom 不会生成 switch 语句,为啥没生成 while 语句之类.要注意,CodeDom只关心代码逻辑,而不是语法,语法是给写代码的人用的.如果用.net的“反编译”工具 ...
- npm 私有模块的管理使用
你可以使用 NPM 命令行工具来管理你在 NPM 仓库的私有模块代码,这使得在项目中使用公共模块变的更加方便. 开始前的工作 你需要一个 2.7.0 以上版本的 npm ,并且需要有一个可以登陆 np ...
- ASP.NET_各个币种之间的汇率转换(实时)使用Yahoo汇率。
近期开发支付平台的时候有运用到各国的实时汇率之间的转换问题,于是在往上找了很多相关资料,以下就是一些参考网址: 1.提供API接口的网站:https://www.showapi.com:这个网站有提供 ...
- Winserver下的Hyper-v “未在远程桌面会话中捕获到鼠标”
异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983.html 服务器相关的知识点:http://www.cnblogs.com/dunitia ...
- C#创建dll类库
类库让我们的代码可复用,我们只需要在类库中声明变量一次,就能在接下来的过程中无数次地使用,而无需在每次使用前都要声明它.这样一来,就节省了我们的内存空间.而想要在类库添加什么类,还需取决于类库要实现哪 ...
- 开源一款简单清爽的日历组件,JavaScript版的
源码会在最后给出地址,需要的朋友自己去下载.最近项目需要做一个日程安排的功能,就是点击日历的某一天弹出一个录入页面,填完信息后保存当天的日程安排.有日程的日期会有不同的标记(比如加一个背景色啥的).网 ...
- 代码的坏味道(22)——不完美的库类(Incomplete Library Class)
坏味道--不完美的库类(Incomplete Library Class) 特征 当一个类库已经不能满足实际需要时,你就不得不改变这个库(如果这个库是只读的,那就没辙了). 问题原因 许多编程技术都建 ...
- ADO.NET编程之美----数据访问方式(面向连接与面向无连接)
最近,在学习ADO.NET时,其中提到了数据访问方式:面向连接与面向无连接.于是,百度了一下,发现并没有很好的资料,然而,在学校图书馆中发现一本好书(<ASP.NET MVC5 网站开发之美&g ...
- jQuery遮罩层登录对话框
用户登录是许多网站必备的功能.有一种方式就是不管在网站的哪个页面,点击登录按钮就会弹出一个遮罩层,显示用户登录的对话框.这用方式比较灵活方便.而现在扫描二维码登录的方式也是很常见,例如QQ.微信.百度 ...
- Android Studio —— 创建Menu菜单项
大多数android程序的右上角都会设置一个菜单按钮比如微信的界面右上角的加号. 这个需要在layout同级目录下新建文件夹命名为menu,再右击新建的menu新建xml文件: