Button Control in VB.net – Windows Form Button Control in VB.net

What is Button Control in VB.net?

A Button Control in VB.net 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 transferring control to the next form.

However, we can set the buttons on the form by using drag and drop operation.

Let’s create a label by dragging a Button control from the Toolbox and dropping it on the form.

Button Control Tutorial in VB.net
Button Control Tutorial in VB.net

Properties of The Button Control in VB.net

The following are some of the commonly used Properties of the Button Control in VB.net.

#Properties of the Button Control in VB.netDescription
1.AutoSizeModeIt is used to get or set the auto mode value through which the button can automatically resize in the Windows form.
2.BackColorIt is used to set the background color of the Button in the Windows form.
3.BackgroundImageIt is used to set the background image of the button control.
4.ForeColorIt is used to set or get the foreground color of the button control.
5.ImageIt is used to set or gets the image on the button control that is displayed.
6.LocationIt is used to set the upper-left of the button control’s coordinates relative to the upper-left corner in the windows form.
7.TextIt is used to set the name of the button control in the windows form.
8.AllowDropIt 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.
9.TabIndexIt is used to set or get the tab order of the button control within the form.
Properties of the Button Control in VB.net

Methods of the Button Control in VB.net

The following are some of the commonly used Methods of Button control in VB.net.

#Methods of the Button Control in VB.netDescription
1.GetPreferredSizeRetrieves the size of a rectangular area into which a control can be fitted.
2.NotifyDefaultNotifies the Button whether it is the default button so that it can adjust its appearance accordingly.
3.SelectActivates the control.
4.ToStringReturns a String containing the name of the Component, if any. This method should not be overridden.
Methods and Description of the Button Control

Events of the Button Control in VB.net

The following are some of the commonly used Events of the Button Control in VB.net.

#Events of the Button Control in VB.netDescription
1.BackColorChangedA BackColorChaged event is found in button control when the Background property is changed.
2.BackgroundImageChangedA BackgoundImageChanged event is found in button control when the value of the BackgoundImage property is changed.
3.ClickA Click event is found in the button control when the control is clicked.
4.ContextManuChangedIt is found in button control when the value of the ContextMenu property is changed.
5.ControlAddedA ControlAdded event is found in button control when a new control is added to the Control.ControlCollection.
6.CursorChangedA CursorChanged event is found in button control when the value of the control is changed.
7.DoubleClickWhen the user makes a double click on the button, a double click event is found in the button control.
8.TextChangedIt is found in the button control when the value of the text property is changed.
9.DragDropThe DragDrop event is found in the button control when the drag and drop operation is completed in the Form.
Events and Description of the Button Control

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

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MsgBox("Hello Planet!!!")

    End Sub
End Class

Program Output:

Button Control in VB.net Output
Button Control Output

Now click on the ‘Click To Say Hi‘ button, it shows the following message on the form.

Button Control in VB.net Message Box Display
Button Control Message Box Display

Summary

In this tutorial, we’ve discussed how to create a Button Control in VB.net using Microsoft Visual Studio.

Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client-side Windows applications.

A Button is a control, which is an interactive component that enables users to communicate with an application which we click and release to perform some actions.


Leave a Comment