The Show Method

The Show method both creates and displays the message box. Visual Basic .NET also takes care of closing the message box. When you click a button, the message box closes, automatically.

The Show method is overloaded. This means that you can call it several different ways, depending on the number of parameters you include. The parameters of the Show method are listed in Table 10-1.

Table 10 -1: Parameters of the Show Method

Parameter

Description

Text

The prompt inside the message box to convey a question or information to the application user, in this case "Do you really want to quit?"

Title

The title of the message box, in this case "Exit application," to provide a visual cue to the application user of the purpose of the message box.

MessageBoxButtons

The buttons inside the message box, in this case Yes and No. The choices are listed in Table 10-2.

MessageBoxIcon

The graphic inside the message box, such as the exclamation mark inFigure 10-1. The choices are listed in Table 10-3.

MessageBoxDefaultButton

The button outlined as a cue that pressing ENTER is the same as clicking the button, in this case the Cancel button. The choices are listed inTable 10-4.

You can call the Show method with only the Text and Title parameters. In that case, the message box only will have one button, OK, which closes the message box when clicked. This may be sufficient if the message box simply provides information to the application user. For example, when filling out a form on a web site, a message box may have popped up telling you that you forgot to fill out a required field, or that the field only takes numbers, or the password must be at least six characters, and so on.

However, the objective of this project is to give the application user a choice of Yes or No concerning whether they really want to quit. You use buttons—here, Yes and No buttons—to give the application user this choice. The MessageBoxButtons enumeration contains the available button combinations, which are listed in Table 10-2.

Table 10-2: MessageBoxButtons Enumeration

Name

Buttons Contained in Message Box

AbortRetrylgnore

Abort, Retry, and Ignore.

OK

OK. This is the default.

OKCancel

OK and Cancel.

Table 10-2: MessageBoxButtons Enumeration

Name

Buttons Contained in Message Box

RetryCancel

Retry and Cancel.

YesNo

Yes and No.

YesNoCancel

Yes, No, and Cancel.

The term enumeration means a list of related choices, which in this case represent the various available button combinations. The syntax of an enumeration is: [Enumeration Name].[Choice Name]

For example, if the selected button combination is Yes and No, the syntax is: MessageBoxButtons.YesNo

MessageBoxButtons is the name of the enumeration, and YesNo is the choice from the enumerated list.

The icon in the message box provides the application user with a visual cue of the nature and importance of the message, ranging from informational to warning or error. Similar to the buttons, the MessageBoxIcon enumeration contains the available icon choices, which are listed inTable 10-3.

Table 10-3: MessageBoxIcon Enumeration

Name

Icon in Message Box

Asterisk

White l owercase letter i in a circle with a blue background.

Error

White X in a circle with a red background.

Exclamation

Black exclamation point in a triangle with a yellow background.

Hand

White X in a circle with a red background.

Information

White lowerc ase letter i in a circle with a blue background.

None

None.

Question

Blue question mark in a circle with a white background.

Stop

White X in a circle with a red background.

Warning

Black exclamation point in a triangle with a yellow background.

Finally, you can designate a default button, which means that the user pressing the ENTER key is the same as the user clicking that button. The MessageBoxDefaultButton enumeration contains the available button choices, which are listed inTable 10-4.

Finally, you can designate a default button, which means that the user pressing the ENTER key is the same as the user clicking that button. The MessageBoxDefaultButton enumeration contains the available button choices, which are listed inTable 10-4.

Table 10-4: MessageBoxDefaultButton Enumeration

Member Name

Description

Buttonl

The first button on the message box is the default b utton.

Button2

The second button on the message box is the default button.

Button3

The third button on the message box is the default

Table 10-4: MessageBoxDefaultButton Enumeration

Member Name

Description

button.

Usually you choose as the default button the one whose choice would have the least drastic effect, if for no other reason than if the application user absentmindedly presses the ENTER key, nothing horrible will happen. Here the button with the least drastic effect is the No button, which will simply restore the status quo.

Was this article helpful?

0 0

Post a comment