GOA - System.Windows.Forms.MessageBox

MessageBox Class


Displays a message box that can contain text, buttons, and symbols that inform and instruct the user.

Definition

public static class MessageBox: Object

Members Table

MethodDescription
EqualsOverloaded. Compares two objects to determine if they are equal. (Inherited from Object)
GetHashCodeServes as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object)
GetTypeGets the Type of the current instance. (Inherited from Object)
ReferenceEqualsDetermines whether the specified Object instances are the same instance. (Inherited from Object)
ShowOverloaded. Shows a MessageBox.
ToStringReturns a String that represents the current Object. (Inherited from Object)

Inheritance Hierarchy

Object
MessageBox

Examples

// 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.SuspendLayout();

 

          this.button1= new Button();

          this.button1.Text= "Show message box";

          this.button1.Width= 160;

          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 );

 

          this.ResumeLayout(false);

     }

 

     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() );

     }

}

 

Class Information

NamespaceSystem.Windows.Forms
Flash LibrarySystem.Windows.Forms.scl
Flash Library Version2.0.0.2118
Silverlight LibrarySystem.Windows.Forms.dll



© 2003-2007 NETiKA Technologies. All rights reserved.