The Message Box in VB .NET

Whenever you have used the Message Box, you have done so like this:

MessageBox.Show( "Your Message Here" )

So you type the word "MessageBox" then a full stop. Double click the "Show" method on the menu that appears. Then type a round bracket. You should get a rather long and complex tool tip appearing:

Message Box options

This is telling you that there are 21 different ways to use the MessageBox function. You are currently viewing the first of these (1 of 21). You can click on the up and down arrows to scroll through then all, if you want.

The first one, though, is "text As String". The text in question is the text that will appear for your message - the message itself, in other words. If you click through to 3 of 21, you see there is another option: "caption As String". This sets the caption at the very top of the message box.

So if your message box function was this:

MessageBox.Show( "This menu will Undo an Operation", "Undo" )

You would get this message box popping up:

A Message Box with a Tiltle

Each option for your message box is separated by a comma. If you type a comma after the "Undo", and then a space, you'll get another pop-up menu. On this menu, you can specify which buttons you want on your message box:

Button options for a NET message box

You only need the OK button on your message boxes. Double click this item, then type another comma, and hit the spacebar. Yet another pop-up menu will appear. On this menu, you can specify the symbol that appears in the message box:

The Information option for a Message Box

It's up to you which symbol you choose. Experiment with all of them and see what they look like. In the image below, we've gone for the Information symbol:

The information symbol on a messaeg box, with an OK button and a Title set

The message box above is a lot better than the first one we tried.


In the next section, we'll move on to Conditional Logic

Click here to explore Conditional Logic in VB .NET -->

<--Back to the .NET Contents Page

View all our Home Study Computer Courses