Button in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the Button control

Button

The Button control is a simple push button and usually you use it to let the user tell the program to do something (selecting an option or making a choice).

A Button control can display a text, a picture, or both.
This figure shows how the button control looks like when you drag and drop to the form in design view:

design view

Change its Text, Image, TextImageRelation and Location properties to make an exit button:

properties

Now that you have the Exit button defined, you have to add some code to make it actually do something.

To add the code for a control, you just double-click the control and it will generate an event handler for you and will open the Code Editor with the following code:

    Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click

    End Sub


This is the shell of the button’s Click event and the place where you enter the code that you want to run when you click the button.
This code is known as an event handler.

Now add the Application.Exit() line to the procedure to make it end the program if button is clicked.

    Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
        Application.Exit()
    End Sub

Previous Lesson | Next Lesson


Share This

Home | About | Contact | Privacy Policy

Copyright © visual-basic-tutorials.com 2017 - All Rights Reserved.