Home » VB.NET Button Control

VB.NET Button Control

by Online Tutorials Library

VB.NET Button Control

Button control is used to perform a click event in Windows Forms, and it can be clicked by a mouse or by pressing Enter keys. It is used to submit all queries of the form by clicking the submit button or transfer control to the next form. However, we can set the buttons on the form by using drag and drop operation.

Let’s create a Button in VB.NET Windows form by using the following steps:

Step 1: We have to drag the Button control from the Toolbox and drop it on the Windows form, as shown below.

VB.NET Button Control

Step 2: Once the button is added to the form, we can set various properties of the Button by clicking on the Button control.

VB.NET Button Properties

Properties Description
AutoSizeMode It is used to get or set the auto mode value through which the button can automatically resize in the Windows form.
BackColor It is used to set the background color of the Button in the Windows form.
BackgroundImage It is used to set the background image of the button control.
ForeColor It is used to set or get the foreground color of the button control.
Image It is used to set or gets the image on the button control that is displayed.
Location It is used to set the upper-left of the button control’s coordinates relative to the upper-left corner in the windows form.
Text It is used to set the name of the button control in the windows form.
AllowDrop It is used to set or get a value representing whether the button control can accept data that can be dragged by the user on the form.
TabIndex It is used to set or get the tab order of the button control within the form.

VB.NET Button Events

BackColorChanged A BackColorChaged event is found in button control when the Background property is changed.
BackgroundImageChanged A BackgoundImageChanged event is found in button control when the value of the BackgoundImage property is changed.
Click A Click event is found in the button control when the control is clicked.
ContextManuChanged It is found in button control when the value of the ContextMenu property is changed.
ControlAdded A ControlAdded event is found in button control when a new control is added to the Control.ControlCollection.
CursorChanged A CursorChanged event is found in button control when the value of the control is changed.
DoubleClick When the user makes a double click on the button, a double click event is found in the button control.
TextChanged It is found in the button control when the value of the text property is changed.
DragDrop The DragDrop event is found in the button control when the drag and drop operation is completed in the Form.

Furthermore, we can also refer to the VB.NET Microsoft documentation to get a complete list of Button properties and events.

Let’s create a program to display a message on the Windows Forms using the button control in VB.NET.

Button_Control.vb

Output:

VB.NET Button Control

Now click on the ‘Click Me’ button, it shows the following message on the form.

VB.NET Button Control

Let’s create another program that displays separate buttons on the form to perform different tasks.

Button_Control.vb

Output:

VB.NET Button Control

Now Click on the Click Me button, it shows the following message on the screen.

VB.NET Button Control

Now click on the Show Image button, it shows the following image on the screen.

VB.NET Button Control

Click on the Exit button to terminate the program.


You may also like