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.
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
||It is used to get or set the auto mode value through which the button can automatically resize in the Windows form.
||It is used to set the background color of the Button in the Windows form.
||It is used to set the background image of the button control.
||It is used to set or get the foreground color of the button control.
||It is used to set or gets the image on the button control that is displayed.
||It is used to set the upper-left of the button control's coordinates relative to the upper-left corner in the windows form.
||It is used to set the name of the button control in the windows form.
||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.
||It is used to set or get the tab order of the button control within the form.
VB.NET Button Events
||A BackColorChaged event is found in button control when the Background property is changed.
||A BackgoundImageChanged event is found in button control when the value of the BackgoundImage property is changed.
||A Click event is found in the button control when the control is clicked.
||It is found in button control when the value of the ContextMenu property is changed.
||A ControlAdded event is found in button control when a new control is added to the Control.ControlCollection.
||A CursorChanged event is found in button control when the value of the control is changed.
||When the user makes a double click on the button, a double click event is found in the button control.
||It is found in the button control when the value of the text property is changed.
||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.
Now click on the 'Click Me' button, it shows the following message on the form.
Let's create another program that displays separate buttons on the form to perform different tasks.
Now Click on the Click Me button, it shows the following message on the screen.
Now click on the Show Image button, it shows the following image on the screen.
Click on the Exit button to terminate the program.