6.5. Implementing the MessageBox Pop-Up Dialog

The MessageBox class allows for the easy generation of a pop-up dialog box. Typically it consists of message text, one or more buttons, and an optional icon such as the information icon pictured in Figure 6.2.

To display the MessageBox dialog, we invoke an instance of its static member function Show(). For example, the following invocation generated the Bad Data Dialog pictured in Figure 6.3:

string messages = "Please enter your name before pressing OK";
string title    = "Bad Data Dialog";

if ( textBox1.Text == string.Empty )
     MessageBox.Show( message, title,
                      MessageBoxButtons.OK,
                      MessageBoxIcon.Warning );

We invoke a four-parameter instance of Show(). The first parameter is the string displayed within ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.