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的更多相关文章

  1. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  2. MessageBox.Show()的各种用法

    [函数] <整型> MessageBox(<字符串> Text, <字符串> Title, <整型> nType,MessageBoxIcon); [函 ...

  3. 简单的 MessageBox

    有时候我们只是想实现一个消息框,给用户一些文字提醒,就像javascript的alert那样.没必要因此动用那些庞大的GUI库,下面是几种轻快的实现方法. 1. ctypes import ctype ...

  4. 自定义类似MessageBox小窗体操作

    1.实际小窗体界面如下 2.代码如下 private void InputBox(string caption,string orderNo) { Form InputForm = new Form( ...

  5. Windows8 UI MessageBox In DevExpress

    // custom messagebox using System; using System.Drawing; using System.Windows.Forms; using DevExpres ...

  6. MessageBox的常用方法

    一 函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd:对话框父窗口句柄, ...

  7. C# MessageBox常用用法

    if(MessageBox.Show("message", "title", MessageBoxButtons.OKCancel,MessageBoxIcon ...

  8. C#中MessageBox用法大全

    我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~&quo ...

  9. winform中messageBox七个参数的使用(转载)

    private void button1_Click(object sender, EventArgs e) { MessageBox.Show(" 1 个参数 ”); } private ...

  10. c# MessageBox 用法大全

    我们在程序中经常会用到MessageBox. 1.MessageBox.Show("Hello~~~~"); 最简单的,只显示提示信息. 2.MessageBox.Show(&qu ...

随机推荐

  1. delphi公共函数 UMyPubFuncFroc--版权所有 (C) 2008 勇者工作室

    {*******************************************************} { } { Delphi公用函数单元 } { } { 版权所有 (C) 2008 勇 ...

  2. 对于div的右浮动会导致顺序会改变

    当我们设置几个div右浮动的时候会出现顺序的改变,直接倒序了. 解决的方法是在几个div外面加上一个大的div即可,但是里面的所有div都要左浮动才行,具体做法如下: <!DOCTYPE htm ...

  3. sql 循环某段时间的每一天

    create table #t1( 日期 datetime) declare @stime datetime;declare @etime datetime set @stime ='2015-01- ...

  4. 如何处理js的跨域问题

    在bill.mail.10086.cn域内访问smsrebuild1.mail.10086.cn下的接口出现“阻止跨域源请求” 例如: URL 说明 是否允许通信 http://www.a.com/a ...

  5. 【原】iOS中KVC和KVO的区别

    在iOS开发中经常会看到KVC和KVO这两个概念,比较可能混淆,特地区分一下 KVC(Key Value Coding) 1> 概述 KVC:Key Value Coding,键值编码,是一种间 ...

  6. 翻译:让网络更快一些——最小化浏览器中的回流(reflow)

    关于reflowreflow(英音:[ri:’fləu] 美音:[ri’flo])在词典中的解释是回流,逆流.而在web应用中,翻译为回流有些牵强.我个人觉得,理解为回炉(重新塑形),似乎更加形象一点 ...

  7. topcoder SRM 624 DIV2 CostOfDancing

    排个序,求前k个元素和即可 int minimum(int K, vector <int> danceCost) { sort(danceCost.begin(),danceCost.en ...

  8. Kosaraju 算法

    Kosaraju 算法 一.算法简介 在计算科学中,Kosaraju的算法(又称为–Sharir Kosaraju算法)是一个线性时间(linear time)算法找到的有向图的强连通分量.它利用了一 ...

  9. POJ 1106 Transmitters(计算几何)

    题目链接 切计算几何,感觉计算几何的算法还不熟.此题,枚举线段和圆点的直线,平分一个圆 #include <iostream> #include <cstring> #incl ...

  10. iOS9 升级XCode7遇到的问题收集

    开发环境运行      各位可能会觉得,笔者在此还要讲开发环境的运行,是不是多此一举.其实并非如此,综合笔者这几年iOS开发经验的总结,运行新版本,特别是测试版本的Xcode是一个需要格外小心的事情, ...