#195 – The Venerable MessageBox

The MessageBox class, in the System.Windows namespace, provides an easy way to display modal dialog boxes.

MessageBox provides a series of overloads of its static Show method, which you call to display a dialog box.

Here are some of the more common overloads:

Text message and a caption

            MessageBox.Show("Truffles are easy to make!", "Chocolate Alert");

.

Specify button(s) that appear on dialog

            MessageBox.Show("Do you like Belgian chocolate?", "Belgians", MessageBoxButton.YesNo);

.

Include buttons and icon

            MessageBox.Show("About to eat last truffle.  Proceed?", "Almost Out", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

.

Buttons, icon and default result

The default result is the MessageBoxResult value that is returned if the user presses Return.

            MessageBoxResult result =
                MessageBox.Show("Have you been to Bruges?", "Lovely Spot", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.No);

.

Options

            MessageBox.Show("In Bruges, I recommend the truffles, the belfry tower and a lovely canal trip.", "Tip", MessageBoxButton.OK,
                MessageBoxImage.Stop, MessageBoxResult.OK, MessageBoxOptions.RightAlign);

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: