WPF - MessageBox Control


MessageBox is a DialogBox Used to inform the Application Status to the End User by displaying Alerts and Warnings. A Simple MessageBox will have DisplayText, Title and OK Button. Depending on the requirement MessageBox can have other buttons and Icons.

MessageBox - Overview


MessageBox is a DialogBox Used to inform the Application Status to the End User by displaying Alerts and Warnings. A Simple MessageBox will have DisplayText, Title and OK Button.
In WPF Application MessageBox is created by using MessageBox Class.
1. It is defined in the System.Windows Class
2. It Represents the Modal Dialog Box
3. It has Show() static Method used to display the Messagebox on the Screen.
Example:
1. Simple MessageBox

MessageBox.Show("Welcome to Training Session");

2. MessageBox with title

// MessageBox with Title
MessageBox.Show("Welcome to Training Session", "Training");

MessageBoxButton
By Default Only OK Button will be displayed on the Messagebox.
The Messagebox can have following Buttons
1.OKCancel - OK and Cancel buttons are displayed.
Example:

// MessageBox with OKCancel button
MessageBox.Show("Do You Want to Attend the Training session", "Training",MessageBoxButton.OKCancel);

2. YesNo - Yes and No buttons are displayed.

// MessageBox with YesNo button
MessageBox.Show("Do You Want to Attend the Training Session", "Training",MessageBoxButton.YesNo);

3. YesNoCancel - Yes,No, and Cancel buttons are displayed

// MessageBox with YesNoCancel button
MessageBox.Show("Do You Want to Attend the Training Session", "Training",MessageBoxButton.YesNoCancel);

MessageBox Icons



Icons can be displayed on the Messagebox to determine the Severity and Importance of the Message. Icons like
-> Hand
-> Question
-> Exclamation
-> Asterisk
-> Stop
-> Error
-> Warning
-> Information
1. MessageBox with Icons

//Messagebox with Buttons and Icons
MessageBox.Show("Do You Want to Attend the Training Session", "Training", MessageBoxButton.YesNo, MessageBoxImage.Question);

2. MessageBox with Icons

//MessageBox with Title, Icon, Yes and No Buttons
string message = "Do You Want to Attend WPF Training Session?";
string caption = "Training";
MessageBoxButton buttons = MessageBoxButton.YesNo;
MessageBoxImage icon = MessageBoxImage.Question;
MessageBox.Show(message, caption, buttons, icon);

Note:Depending on the Importance and Significance of the Message Appropriate Icons should be used.


Comments

Author: shalini rathore14 Mar 2012 Member Level: Bronze   Points : 0

gud one......
and full information about message box in wpf.
thanks...

Author: Vijayalakshmi G M14 Mar 2012 Member Level: Gold   Points : 0

Thank you Shalini for your valuable comments.

Share this Article with you friends.

Guest Author: Mboute19 Mar 2012

oh I see I haven't had an SBSC specific action pack yet think i just missed the last one..must look into that I'm interested in the SharePoint event.would like to go if the diary allows!



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: