If you create a message box with more than one button, the most left button usually has a thick border, indicating that it is the default. If the user presses Enter after viewing the button, the effect would be the same as if he had clicked the default button. If you want, you can designate another button as the default. To do this, you can use or add another member of the MsgBoxStyle enumeration. The members used to specify the default button are:
Once again, to specify a default value, use the OR operator to combine a Default Button Constant with any other combination. Here is an example: Public Function Main() As Integer MsgBox("Your logon credentials have been checked " & _ "and your application has been approved: Congratulations!" & _ vbCrLf & "Before leaving, would you like " & _ "to take our survey survey now?", _ MsgBoxStyle.YesNo Or _ MsgBoxStyle.Question Or MsgBoxStyle.DefaultButton2) Return 0 End Function This would produce: These additional buttons can be used to further control what the user can do:
The Title argument is the caption that would display on the title bar of the message box. It is a string whose word or words you can enclose between parentheses or that you can get from a created string. The Title argument is optional. As you have seen so far, if you omit, the message box would display the name of the application on the title bar. Otherwise, if you want a custom title, you can provide it as the third argument to the MsgBox() function. The caption can be a simple string. Here is an example: Public Function Main() As Integer MsgBox("Your logon credentials have been checked " & _ "and your application has been approved: Congratulations!" & _ vbCrLf & "Before leaving, would you like " & _ "to take our survey survey now?", _ MsgBoxStyle.YesNo Or MsgBoxStyle.Question, _ "Crofton Circle of Friends - Membership Application") Return 0 End Function This would produce: Notice that the caption is now customized instead of the name of the application. The caption can also be a string created from an expression or emanating from a variable or value.
The MsgBox() function can be used to return a value. This value corresponds to the button the user clicked on the message box. Depending on the buttons the message box is displaying, after the user has clicked, the MsgBox() function can return a value. The value can be a member of the MsgBoxResult enumeration or a constant numeric value recognized by the Visual Basic language. The value returned can be one of the following values:
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|