- VB.Net Basic Tutorial
- VB.Net - Home
- VB.Net - Overview
- VB.Net - Environment Setup
- VB.Net - Program Structure
- VB.Net - Basic Syntax
- VB.Net - Data Types
- VB.Net - Variables
- VB.Net - Constants
- VB.Net - Modifiers
- VB.Net - Statements
- VB.Net - Directives
- VB.Net - Operators
- VB.Net - Decision Making
- VB.Net - Loops
- VB.Net - Strings
- VB.Net - Date & Time
- VB.Net - Arrays
- VB.Net - Collections
- VB.Net - Functions
- VB.Net - Subs
- VB.Net - Classes & Objects
- VB.Net - Exception Handling
- VB.Net - File Handling
- VB.Net - Basic Controls
- VB.Net - Dialog Boxes
- VB.Net - Advanced Forms
- VB.Net - Event Handling
- VB.Net Advanced Tutorial
- VB.Net - Regular Expressions
- VB.Net - Database Access
- VB.Net - Excel Sheet
- VB.Net - Send Email
- VB.Net - XML Processing
- VB.Net - Web Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
VB.Net - Button Control
63 Lectures 4 hours
60 Lectures 9.5 hours
The Button control represents a standard Windows button. It is generally used to generate a Click event by providing a handler for the Click event.
Let's create a label by dragging a Button control from the Toolbox ad dropping it on the form.
Properties of the Button Control
The following are some of the commonly used properties of the Button control −
|Sr.No.||Property & Description|
Gets or sets the mode by which the Button automatically resizes itself.
Gets or sets the background color of the control.
Gets or sets the background image displayed in the control.
Gets or sets a value that is returned to the parent form when the button is clicked. This is used while creating dialog boxes.
Gets or sets the foreground color of the control.
Gets or sets the image that is displayed on a button control.
Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.
Gets or sets the tab order of the control within its container.
Gets or sets the text associated with this control.
Methods of the Button Control
The following are some of the commonly used methods of the Button control −
|Sr.No.||Method Name & Description|
Retrieves the size of a rectangular area into which a control can be fitted.
Notifies the Button whether it is the default button so that it can adjust its appearance accordingly.
Activates the control.
Returns a String containing the name of the Component, if any. This method should not be overridden.
Events of the Button Control
The following are some of the commonly used events of the Button control −
|Sr.No.||Event & Description|
Occurs when the control is clicked.
Occurs when the user double-clicks the Button control.
Occurs when the control receives focus.
Occurs when the TabIndex property value changes.
Occurs when the Text property value changes.
Occurs when the control is finished validating.
Consult Microsoft documentation for detailed list of properties, methods and events of the Button control.
In the following example, we create three buttons. In this example, let us −
Set captions for the buttons
Set some image for the button
Handle the click events of each buttons
Take following steps −
Drag and drop a Label control on the form.
Set the Text property to provide the caption "Tutorials Point".
Drag and drop three buttons on the form.
Using the properties window, change the Name properties of the buttons to btnMoto, btnLogo and btnExit respectively.
Using the properties window, change the Text properties of the buttons to Show Moto, Show Logo and Exit respectively.
Drag and Drop another button, using the properties window, set its Image property and name it btnImage.
At this stage, the form looks like −
Click the form and add following code in the code editor −
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Set the caption bar text of the form. Me.Text = "tutorialspont.com" btnImage.Visible = False End Sub Private Sub btnMoto_Click(sender As Object, e As EventArgs) Handles btnMoto.Click btnImage.Visible = False Label1.Text = "Simple Easy Learning" End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Application.Exit() End Sub Private Sub btnLogo_Click(sender As Object, e As EventArgs) Handles btnLogo.Click Label1.Visible = False btnImage.Visible = True End Sub End Class
Clicking the first button, displays −
Clicking the second button displays −
Clicking the third button, exits the application.