Message Boxes In Visual Basic 2010

Message Boxes In Visual Basic 2010

Message Boxes are probably the most basic events which are created in Visual Basic Windows Forms Applications. They are used to display messages. You can also add modifications in displaying messages. Like, you can add icons to your messages or add a title for your windows form.

First of all; create a new form and add a button. Double click on the button you created in the design window. The code window will open.

Below you can check various methods of defining message boxes.

  1. MessageBox.Show(“your message”)
    This is used when you want to display a bare message. i.e, when you want to display a message in a window which doesn’t contain a title or an icon.

    Output:

    Message Boxes 1

  2. MessageBox.Show(“your message”, “title”)
    This is used when you display a message along with a title for your windows form. The first parameter in the message box is the message and the second parameter is the title for the windows form.

    Output:
    Message Boxes 2

  3. MessageBox.Show(“your message”, “title”, MessageBoxButtons.OK, MessageBoxIcon.Hand)
    This is used when you want to display a message and a title and an icon at the beginning of your message. The system also produces a sound corresponding to the icon you have chosen. In our example, we have chosen the icon hand. You can also choose the icons such as information, stop, warning, and etc. which are available in Visual Basic.

    Output:
    Message Boxes 3

Important:

You can also make use of short-hand coding in creating message boxes. Check out below:

Output:

Message Boxes 4

Additionally; it is important to be noted that in this case the system will make use of a default Visual Basic title for the message box which is “Message Boxes”.

Read Also:   Introduction To Windows Forms Application In Visual Basic

Further On Message Boxes

You can create further events on Message Boxes in Visual Basic. In the examples above the only button that we have used is the “OK” button. Moreover; you can make use of several other buttons. Check the example below:

Example: In this example we have used the “Yes” and “No” button and further we have created a message box for “Yes” button. We have simple made use of a simple “If Statement”. Further; we will discuss more about “If Statements” and so on.

Output:

Message Boxes 5

You can further play around with other buttons such as “OkCancel” and more. Further; we will show you how to use “If Statements” and “IfElse Statements” so that you may be able to create message boxes for all other buttons you have created in your codes.

Previous Introduction to Windows Forms Application in Visual Basic 2010
Next Sub Procedures and Input Boxes in Visual Basic 2010

About author

Bahonar Javid
Bahonar Javid 43 posts

* Computer Application Student * Co-Founder of www.codejow.com * Love to code and Learn new languages * Enjoy playing football

View all posts by this author →

You might also like