How to Right-Align a Text List in a Visual Basic Message Box

By default, the MsgBox function in Visual Basic requires only the message or prompt parameter. However, a second parameter is available that lets you use the MsgBoxStyle enumeration to customize the message box's appearance, including the text alignment. To display a text list in a message box, first create a string variable to store the list and add new lines after each list item, and then call the MsgBox function and use the "MsgBoxRight" value to right-align the text.

Instructions

    • 1

      Open your Visual Basic project. Double-click the "Button" tool to add it to the form. Double-click the control on the form to open the "Button1_Click" function.

    • 2

      Type the following:

      Dim strVar1 As String = "One"

      Dim strVar2 As String = "Two"

      Dim strVar3 As String = "Three"

      Dim message As String

      This declares three string variables to use as a list of text. You can use any other variables, including an array of strings in place of these three.

    • 3

      Type the following:

      message = strVar1 & vbNewLine & strVar2 & vbNewLine & strVar3

      This initializes the "message" variable with the string text. Use a loop if you have an array of strings. Calling "vbNewLine" after each string inserts a new line into the text to make it into a list.

    • 4

      Type the following:

      MsgBox(message, MsgBoxStyle.MsgBoxRight)

      This creates a message box that displays the list of text saved in the "message" variable and uses the "MsgBoxStyle" enumeration to right-align the text.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured