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.


Message Box in VB .NET

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


Source Code:

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

    Private Sub btnexample2_Click(sender As Object, e As EventArgs) Handles btnexample2.Click
        MessageBox.Show("Welcome to studentprojectguide.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

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


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

messagebox example with message and title


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

messagebox example with message, title and button


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


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


Download Source Code:

free student projects


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

🔥274 Views

Anu

Leave a Reply

Your email address will not be published. Required fields are marked *

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