Message Box in VB .NET

Message Box in VB .NET

Message Box in VB .NET – Working with messagebox is a very interesting topic for beginners. The message box which displays dialog box in VB.NET.  It is used to display a error messages, notification, etc. This tutorial helps you to learn main features of message box. In the example we created program of simple messagebox, Message box with title, dialog box with buttons, dialog box with icons, and dialog box with if else condition.

[themepacific_divider style=”solid”]

Message Box in VB .NET

Basic Syntax: MessageBox.Show(message, title, controls, icon)

[themepacific_divider style=”solid”]

Source Code:

Public Class frmmessagebox
    Private Sub btnexample1_Click(sender As Object, e As EventArgs) Handles btnexample1.Click
        MessageBox.Show("Welcome to www.sourcecodefiles.com")
    End Sub

    Private Sub btnexample2_Click(sender As Object, e As EventArgs) Handles btnexample2.Click
        MessageBox.Show("Welcome to www.sourcecodefiles.com", "Welcome Message..")
    End Sub

    Private Sub btnexample3_Click(sender As Object, e As EventArgs) Handles btnexample3.Click
        MessageBox.Show("Hello visitors", "Study well", MessageBoxButtons.YesNo)
    End Sub

    Private Sub btnexample4_Click(sender As Object, e As EventArgs) Handles btnexample4.Click
        MessageBox.Show("This messagebox with icon", "Example 4", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)
    End Sub

    Private Sub btnexample5_Click(sender As Object, e As EventArgs) Handles btnexample5.Click
        dim msgresult As DialogResult = MessageBox.Show("Press Ok or Cancel", "Confirmation Box", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk)
         If msgresult = DialogResult.OK Then
            MessageBox.Show("You clicked OK button")
        Else
            MessageBox.Show("You clicked Cancel button")
        End If
    End Sub
End Class

[themepacific_divider style=”solid”]

Example 1: In the example 1 just it displays message in the content bar and default OK button comes under this.

messagebox example with message

[themepacific_divider style=”solid”]

Example 2: In this example The dialog box appears with message and title in the top.

messagebox example with message and title

[themepacific_divider style=”solid”]

Example 3: This is 3 argument dialog box with message, title and multiple buttons.

messagebox example with message, title and button

[themepacific_divider style=”solid”]

Example 4: This message box has 4 arguments with message, title, button type and it displays icon

messagebox example with message, title, button and icon

[themepacific_divider style=”solid”]

Example 5: In the following example conditions given for two buttons. If user clicks OK then if condition executes and if user clicks cancel then else statement executes.

messagebox example with if else condition

[themepacific_divider style=”solid”]

Download Source Code:

free student projects

[themepacific_divider style=”solid”]

Video Tutorial: This video tutorial gives details explanation of messagebox.

Anu

Do you have any queries?

This site uses Akismet to reduce spam. Learn how your comment data is processed.