Displays a message box that can contain text, buttons, and symbols that inform and instruct the user.
public static class MessageBox: Object
ObjectMessageBox
// This sample shows how to display a message box.
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
Button button1;
Label label1;
public MyForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.button1
= new Button();this.button1.Text= "Show message box";
this.button1.Location= new Point(30,30);
this.button1.Click += new EventHandler(on_click);
this.label1= new Label();
this.label1.Size= new Size(Application.Width-50,60);
this.label1.Location= new Point(30,30+40);
this.label1.Text= "The message box has not yet been displayed.";
this.Controls.Add( this.button1 );
this.Controls.Add( this.label1 );
}
private void on_click( object sender, EventArgs e )
{
// Note that the ShowDialog method is asynchronous and returns immediately.
// To retrieve the dialog result, one must intercept the Closed event as
// illustrated in this sample code.
DialogResultListener drl;
drl= MessageBox.Show( "You have pressed the button!",
"Simple Message Box",
MessageBoxButtons.OKCancel );
drl.Closed += new EventHandler(on_msgbox_closed);
}
private void on_msgbox_closed( object sender, EventArgs e )
{
DialogResultListener drl= (DialogResultListener) sender;
string res= "<unknow result>";
if( drl.DialogResult == DialogResult.OK )
res= "OK";
else if( drl.DialogResult == DialogResult.Cancel )
res= "Cancel";
this.label1.Text= "The message box result is : " + res;
}
static void Main()
{
Application.Run( new MyForm() );
}
}
Namespace System.Windows.Forms Flash Library System.Windows.Forms.scl Flash Library Version 2.0.0.2118 Silverlight Library System.Windows.Forms.dll
| © 2003-2007 NETiKA Technologies. All rights reserved. |