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.
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.