MessageBox Class
Examples
http://msdn.microsoft.com/en-us/library/aa969773(v=vs.110).aspx
Displays a message box that can contain text, buttons, and symbols that inform and instruct the user.
MessageBoxButtons.YesNo
const string message = "您想删除当前记录吗?";
const string caption = "删除当前记录";
var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
//delete the current record }
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
const string message =
"Are you sure that you would like to close the form?";
const string caption = "Form Closing";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question); // If the no button was pressed ...
if (result == DialogResult.No)
{
// cancel the closure of the form.
e.Cancel = true;
}
}
private void validateUserEntry()
{ // Checks the value of the text. if(serverName.Text.Length == 0)
{ // Initializes the variables to pass to the MessageBox.Show method. string message = "You did not enter a server name. Cancel this operation?";
string caption = "Error Detected in Input";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result; // Displays the MessageBox. result = MessageBox.Show(message, caption, buttons); if (result == System.Windows.Forms.DialogResult.Yes)
{ // Closes the parent form. this.Close(); } } }
// Handles the ComboBox1 DropDown event. If the user expands the
// drop-down box, a message box will appear, recommending the
// typical installation.
private void ComboBox1_DropDown(object sender, System.EventArgs e)
{
MessageBox.Show("Typical installation is strongly recommended.",
"Install information", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
MessageBoxButtons Enumeration
| Member name | Description | |
|---|---|---|
| AbortRetryIgnore | The message box contains Abort, Retry, and Ignore buttons. | |
| OK | The message box contains an OK button. | |
| OKCancel | The message box contains OK and Cancel buttons. | |
| RetryCancel | The message box contains Retry and Cancel buttons. | |
| YesNo | The message box contains Yes and No buttons. | |
| YesNoCancel | The message box contains Yes, No, and Cancel buttons. |
MessageBoxIcon Enumeration
| Member name | Description | |
|---|---|---|
| Asterisk | The message box contains a symbol consisting of a lowercase letter i in a circle. | |
| Error | The message box contains a symbol consisting of white X in a circle with a red background. | |
| Exclamation | The message box contains a symbol consisting of an exclamation point in a triangle with a yellow background. | |
| Hand | The message box contains a symbol consisting of a white X in a circle with a red background. | |
| Information | The message box contains a symbol consisting of a lowercase letter i in a circle. | |
| None | The message box contain no symbols. | |
| Question | The message box contains a symbol consisting of a question mark in a circle. The question-mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility. | |
| Stop | The message box contains a symbol consisting of white X in a circle with a red background. | |
| Warning | The message box contains a symbol consisting of an exclamation point in a triangle with a yellow background. |
DialogResult
| Member name | Description | |
|---|---|---|
| Abort | The dialog box return value is Abort (usually sent from a button labeled Abort). | |
| Cancel | The dialog box return value is Cancel (usually sent from a button labeled Cancel). | |
| Ignore | The dialog box return value is Ignore (usually sent from a button labeled Ignore). | |
| No | The dialog box return value is No (usually sent from a button labeled No). | |
| None | Nothing is returned from the dialog box. This means that the modal dialog continues running. | |
| OK | The dialog box return value is OK (usually sent from a button labeled OK). | |
| Retry | The dialog box return value is Retry (usually sent from a button labeled Retry). | |
| Yes | The dialog box return value is Yes (usually sent from a button labeled Yes). |
if(dr == DialogResult.Cancel)
{
e.Cancel = true;
}
else
{
if(dr == DialogResult.Yes)
{
//Save the data
}
}
DialogResult dr = MessageBox.Show("Do You Want to Save Data?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
//e.Cancel = false ;
}
else if (dr == DialogResult.Cancel)
{
//e.cancel = true ;
}
else
{
}
How to: Retrieve Data from a Dialog Box
http://msdn.microsoft.com/en-us/library/bb383855(v=vs.90).aspx
Key =>
Form2 subForm = new Form2(this);
subForm.Show();
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void addItems_Click(object sender, EventArgs e)
{
Form2 subForm = new Form2(this);
subForm.Show();
}
} public partial class Form2 : Form
{
Form1 mainForm; public Form2(Form1 mainForm)
{
this.mainForm = mainForm; InitializeComponent();
} private void okButton_Click(object sender, EventArgs e)
{
if (this.textBox1.Text != string.Empty)
{ mainForm.listBox1.Items.Clear(); string[] stringsEntered = textBox1.Lines; for (int count = ; count < stringsEntered.Length; count++)
{ mainForm.listBox1.Items.Add(stringsEntered[count]); } }
this.Close(); }
}
END
MessageBox Class的更多相关文章
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- MessageBox.Show()的各种用法
[函数] <整型> MessageBox(<字符串> Text, <字符串> Title, <整型> nType,MessageBoxIcon); [函 ...
- 简单的 MessageBox
有时候我们只是想实现一个消息框,给用户一些文字提醒,就像javascript的alert那样.没必要因此动用那些庞大的GUI库,下面是几种轻快的实现方法. 1. ctypes import ctype ...
- 自定义类似MessageBox小窗体操作
1.实际小窗体界面如下 2.代码如下 private void InputBox(string caption,string orderNo) { Form InputForm = new Form( ...
- Windows8 UI MessageBox In DevExpress
// custom messagebox using System; using System.Drawing; using System.Windows.Forms; using DevExpres ...
- MessageBox的常用方法
一 函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd:对话框父窗口句柄, ...
- C# MessageBox常用用法
if(MessageBox.Show("message", "title", MessageBoxButtons.OKCancel,MessageBoxIcon ...
- C#中MessageBox用法大全
我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~&quo ...
- winform中messageBox七个参数的使用(转载)
private void button1_Click(object sender, EventArgs e) { MessageBox.Show(" 1 个参数 ”); } private ...
- c# MessageBox 用法大全
我们在程序中经常会用到MessageBox. 1.MessageBox.Show("Hello~~~~"); 最简单的,只显示提示信息. 2.MessageBox.Show(&qu ...
随机推荐
- Codeforces Round #342 (Div. 2)
贪心 A - Guest From the Past 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...
- MFC listcontrol 分列 添加行数据 点击列头排序
适用于 对话框程序 1.在工具箱中拖出 ListControl,然后右键-属性,view-Report 让你的ListControl变成这幅模样! 2.添加ListControl控件的control类 ...
- POJ2976 Dropping tests(01分数规划)
题目大概说给n个二元组Ai和Bi,要去掉k个,求余下的100*∑Ai/∑Bi的最大值. 假设要的最大的值是ans,令Di=Ai-ans*∑Bi,对Di排序取最大的n-k个,如果∑Ai-ans*∑Bi& ...
- Modify a Stored Procedure using SQL Server Management Studio
In Object Explorer, connect to an instance of Database Engine and then expand that instance. Expand ...
- jQuery的封装和扩展方式
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- HDU 1686 & KMP
题意: 求模板在匹配串所有子串中出现次数. SOL: 本题与普通kmp有一点不同,因为待匹配串中的模板串可能相互包含. 我们考虑正常的kmp是在怎么做的 i = 1 2 3 4 5 6 7 8 9 … ...
- 未能加载文件或程序集"Microsoft.Web.Infrastructure 的解决方案
转载请注明来源: http://www.cnblogs.com/zaiyuzhong/p/Unload-Infrastructure-Solution.html 部署MVC5 项目发布到文件系统 I ...
- 20145308刘昊阳 《Java程序设计》第2周学习总结
20145308刘昊阳 <Java程序设计>第2周学习总结 教材学习内容总结 第三章 基础语法 3.1 类型.变量与运算符 类型 基本类型 整数(short/int/long) short ...
- jquery实现隐藏,简化和更多
HTML代码: <div class="box"> <div class="header"> <h3>图书分类</h3 ...
- CentOS VirtualBox启动虚拟及报错:VirtualBox error: Kernel driver not installed (rc=1908)
VirtualBox error: Kernel driver not installed (rc=1908) Hi all, Let me first say that this is my fin ...