MessageBox.Show方法小结
2012-08-31 15:06
183 查看
MessageBox.Show方法(String,String,MessageBoxButtons)
http://msdn.microsoft.com/zh-cn/library/0x49kd7z(v=vs.80).aspx
显示具有指定文本、标题和按钮的消息框。
命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在system.windows.forms.dll中)
publicstaticDialogResultShow(
stringtext,
stringcaption,
MessageBoxButtonsbuttons
)
参数
Text要在消息框中显示的文本。
Caption要在消息框的标题栏中显示的文本。
ButtonsMessageBoxButtons值之一,可指定在消息框中显示哪些按钮。
返回值
DialogResult值之一。
下面的代码示例演示如何使用受此Show重载支持的选项显示一个MessageBox。验证字符串变量ServerName为空后,此示例显示一个MessageBox,为用户提供取消该操作的选项。如果Show方法的返回值计算为Yes,则将关闭显示MessageBox的窗体。
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.messageboxbuttons(v=vs.80).aspx
指定若干常数,用以定义MessageBox上将显示哪些按钮
命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在system.windows.forms.dll中)
显示具有指定文本、标题和按钮的消息框。
命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在system.windows.forms.dll中)
publicstaticDialogResultShow(
stringtext,
stringcaption,
MessageBoxButtonsbuttons
)
参数
Text要在消息框中显示的文本。
Caption要在消息框的标题栏中显示的文本。
Buttons
返回值
下面的代码示例演示如何使用受此
privatevoidvalidateUserEntry()
{
//Checksthevalueofthetext.
if(serverName.Text.Length==0)
{
//InitializesthevariablestopasstotheMessageBox.Showmethod.
stringmessage="Youdidnotenteraservername.Cancelthisoperation?";
stringcaption="ErrorDetectedinInput";
MessageBoxButtonsbuttons=MessageBoxButtons.YesNo;
DialogResultresult;
//DisplaystheMessageBox.
result=MessageBox.Show(message,caption,buttons);
if(result==DialogResult.Yes)
{
//Closestheparentform.
this.Close();
}
}
}
MessageBoxButtons枚举
指定若干常数,用以定义
命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在system.windows.forms.dll中)
AbortRetryIgnore | 消息框包含“中止”、“重试”和“忽略”按钮。 | |
OK | 消息框包含“确定”按钮。 | |
OKCancel | 消息框包含“确定”和“取消”按钮。 | |
RetryCancel | 消息框包含“重试”和“取消”按钮。 | |
YesNo | 消息框包含“是”和“否”按钮。 | |
YesNoCancel | 消息框包含“是”、“否”和“取消”按钮。 |
privatevoidbutton1_Click(objectsender,System.EventArgse){
if(textBox1.Text==""){
MessageBox.Show("Youmustenteraname.","NameEntryError",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
else{
//Codetoactonthedataenteredwouldgohere.
}
}
相关文章推荐
- Ext.MessageBox.show()方法的使用
- 小杂项,MessageBox.Show()的响应方法,""和null,MessageBox.Show()常用参数
- mousemove事件以及MessageBox.show()方法
- MessageBox.Show();报最匹配的重载方法具有一些无效参数解决方法
- C#中MessageBox.Show()方法详解
- Ext.MessageBox.show()方法的使用
- messagebox.show使用方法
- C#中的MessageBox的show的各种重载方法使用
- MessageBox.Show常用的2个方法
- C#中MessageBox.Show()实用方法
- asp.net 2.0中的MessageBox.Show()方法
- MessageBox.Show 使用方法
- MessageBox.Show 方法使用:
- c/s项目中MessageBox.show()方法参数讨论
- C#中可以固定MessageBox.Show的方法
- Ext.MessageBox.show()方法的使用
- C# WinForm中实现MessageBox.Show()的常用方法
- Ext.MessageBox.show()方法的使用
- MessageBox.Show方法出现“容量超出了最大容量。参数名: capacity”错误!
- Ext.MessageBox学习,包括alert,confirm,prompt,wait和show的使用方法