Dialogs in Visual Basic

In addition to OkOnly and YesNo the other MsgBoxStyle values are shown below. The MsgBoxStyle is shown as the prompt
msg  msg

msg  msg

You can also display an icon along with these buttons by adding one of the values below to one of the values above. The message box below was displayed with the statement:

Ans = MsgBox("Icons", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "MsgBox")
msg

The following MsgBoxStyles can be selected: Criticalmsg, Questionmsg, Exclamationmsg, and Informationmsg.


Notice that the message box above has Yes selected as the default. If the user presses Enter, it is the same as clicking Yes. You can change the default selection by adding DefaultButton2 or DefaultButton3:

Ans = MsgBox("Icons", MsgBoxStyle.YesNo + _
  MsgBoxStyle.Information + MsgBoxStyle.DefaultButton2, "MsgBox")

Note: Only one icon and one default button can be included. Experiment with as many different combinations as you can.

NEXT: Dialog Boxes