VB.Net - Button Control

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.
The following are some of the commonly used properties of the Button control −
AutoSizeMode
Gets or sets the mode by which the Button automatically resizes itself.
BackColor
Gets or sets the background color of the control.
BackgroundImage
Gets or sets the background image displayed in the control.
DialogResult
Gets or sets a value that is returned to the parent form when the button is clicked. This is used while creating dialog boxes.
ForeColor
Gets or sets the foreground color of the control.
Image
Gets or sets the image that is displayed on a button control.
Location
Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.
TabIndex
Gets or sets the tab order of the control within its container.
Text
Gets or sets the text associated with this control.
The following are some of the commonly used methods of the Button control −
GetPreferredSize
Retrieves the size of a rectangular area into which a control can be fitted.
NotifyDefault
Notifies the Button whether it is the default button so that it can adjust its appearance accordingly.
Select
Activates the control.
ToString
Returns a String containing the name of the Component, if any. This method should not be overridden.
The following are some of the commonly used events of the Button control −
Click
Occurs when the control is clicked.
DoubleClick
Occurs when the user double-clicks the Button control.
GotFocus
Occurs when the control receives focus.
TabIndexChanged
Occurs when the TabIndex property value changes. 
TextChanged
Occurs when the Text property value changes.
Validated
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 captions for the buttons
Set some image for the button
Set some image for the button
Handle the click events of each buttons
Handle the click events of each buttons
Take following steps −
Drag and drop a Label control on the form.
Drag and drop a Label control on the form.
Set the Text property to provide the caption "Tutorials Point".
Set the Text property to provide the caption "Tutorials Point".
Drag and drop three buttons on the form.
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 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.
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.
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.

    63 Lectures 
     4 hours 

 Frahaan Hussain

    103 Lectures 
     12 hours 

 Arnold Higuit

    60 Lectures 
     9.5 hours 

 Arnold Higuit

    97 Lectures 
     9 hours 

 Arnold Higuit
 Print
 Add Notes
 Bookmark this page