MessageBox Class

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
                {

                }

MessageBox Class

时间: 2024-10-28 23:46:30

MessageBox Class的相关文章

C#中MessageBox用法大全(转)

我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~"); 最简单的,只显示提示信息. 2.MessageBox.Show("There are something wrong!","ERROR"); 可以给消息框加上标题. 3.if (MessageBox.Show("Delete this user?&q

C# MessageBox常用用法

if(MessageBox.Show("message", "title", MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2) == DialogResult.OK) { MessageBox.Show("chose OK", "title"); } else { MessageBox.Show("c

C# MessageBox 消息对话框

在程序中,我们经常使用消息对话框给用户一定的信息提示,如在操作过程中遇到错误或程序异常,经常会使用这种方式给用于以提示.在C#中,MessageBox消息对话框位于System.Windows.Forms命名空间中,一般情况,一个消息对话框包含信息提示文字内容.消息对话框的标题文字.用户响应的按钮及信息图标等内容.C#中允许开发人员根据自己的需要设置相应的内容,创建符合自己要求的信息对话框. MessageBox消息对话框只提供了一个方法Show(),用来把消息对话框显示出来.此方法提供了不同的

MessageBox

MessageBox对话框是比较常用的一个信息对话框,其不仅能够定义显示的信息内容.信息提示图标,而且可以定义按钮组合及对话框的标题,是一个功能齐全的信息对话框信息提示图标,而且可以定义按钮组合及对话框的标题,是一个功能齐全的信息对框. 1.函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; //hWnd:对话框父窗口句柄,对话框显示在Delphi窗体内,可使用窗体的Handle属

AfxMessageBox和MessageBox差别

假设用MFC的话,请尽量使用afxmessagebox,由于这个全局的对话框最安全,也最方便.   可是在WIN32 SDK的情况下仅仅能使用MESSAGEBOX. MessageBox()是Win32API函数.后者是mfc中的全局函数.在MFC中能用MessageBox()的地方都能用AfxMessageBox(). afxmessagebox很多其它的时候是用于调试AfxMessageBox 比 MessageBox 方便!    MessageBox 比 AfxMessageBox 灵活

ExtJS学习第一天 MessageBox

此文用来记录学习笔记: •学习任何技术,首先都要从Helloworld开始,那么我们首要任务就是写一个简单的HelloWorld程序,带领同学们走进ExtJS的世界. •Ext.onReady:这个方法是Ext的准备函数,也就是Ext相关的代码都会在这个函数里书写,它比较类似于window的onload方法,但是注意其执行时机是在页面的DOM对象加载完毕之后立即执行. •Ext.window.MessageBox:这个类提供了ExtJS的弹出提示框.确认框等简单的小组件.我们首先根据它写出我们的

[转载]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 (IWi

MessageBox.Show()的各种用法

[函数] <整型> MessageBox(<字符串> Text, <字符串> Title, <整型> nType,MessageBoxIcon); [函数说明] 弹出一个消息框. [语法] 参数: Text <字符串>,消息框的正文: Title <字符串>,消息框的标题: nType <整型>,消息框的类型. 返回值:<整型>,用户在消息框上点击关闭时的选择的按钮. MessageBoxIcon:对话框上显示

MessageBox.Show()和三级联动

1  MessageBox.Show() 弹出消息框时有确定和取消按钮MessageBoxButtons.OKCancel参数1:提示信息,参数2:消息框标题,参数3:信息框类型 DialogResult dd = MessageBox.Show("是否删除" + li.SubItems[3].Text, "提示", MessageBoxButtons.OKCancel); if(dd==DialogResult.OK) //单击确定按钮{}else//单击取消按钮

Extended MessageBox Library (assembly) for .NET

Apr 30, 2010. Summary: With this library .NET applications can control a wide variety of MessageBox dialog settings. That includes adjusting initial position and size of the dialog, selecting message font and font color, filling dialog background wit