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 transfer control to the next form. However, we can set the buttons on the form by using drag and drop operation.
Table of contents
See also all the Basic Control Using VB.net with Source Code….
In order for you to test your VB.net Code provided in this lesson, you must test the code in your code editor. But if you wish to run this code online, we also have an Online Compiler in VB.net for you to test your VB.net Code for free.
We have learned how to use the Label Control in VB.net in the previous lesson. In this lesson we shall learn How To Write a Program for Button Control in VB.net.
Let’s create a label by dragging a Button control from the Toolbox ad dropping it on the form.
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.net||Description|
|1.||AutoSizeMode||It is used to get or set the auto mode value through which the button can automatically resize in the Windows form.|
|2.||BackColor||It is used to set the background color of the Button in the Windows form.|
|3.||BackgroundImage||It is used to set the background image of the button control.|
|4.||ForeColor||It is used to set or get the foreground color of the button control.|
|5.||Image||It is used to set or gets the image on the button control that is displayed.|
|6.||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.|
|7.||Text||It is used to set the name of the button control in the windows form.|
|8.||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.|
|9.||TabIndex||It is used to set or get the tab order of the button control within the form.|
Methods of the Button Control in VB.net
The following are some of the commonly used Methods of the Button control in VB.net.
|#||Methods of the Button Control in VB.net||Description|
|1.||GetPreferredSize||Retrieves the size of a rectangular area into which a control can be fitted.|
|2.||NotifyDefault||Notifies the Button whether it is the default button so that it can adjust its appearance accordingly.|
|3.||Select||Activates the control.|
|4.||ToString||Returns a String containing the name of the Component, if any. This method should not be overridden.|
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.net||Description|
|1.||BackColorChanged||A BackColorChaged event is found in button control when the Background property is changed.|
|2.||BackgroundImageChanged||A BackgoundImageChanged event is found in button control when the value of the BackgoundImage property is changed.|
|3.||Click||A Click event is found in the button control when the control is clicked.|
|4.||ContextManuChanged||It is found in button control when the value of the ContextMenu property is changed.|
|5.||ControlAdded||A ControlAdded event is found in button control when a new control is added to the Control.ControlCollection.|
|6.||CursorChanged||A CursorChanged event is found in button control when the value of the control is changed.|
|7.||DoubleClick||When the user makes a double click on the button, a double click event is found in the button control.|
|8.||TextChanged||It is found in the button control when the value of the text property is changed.|
|9.||DragDrop||The DragDrop event is found in the button control when the drag and drop operation is completed in the Form.|
Let’s create a program to display a message on the 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
Now click on the ‘Click To Say Hi‘ button, it shows the following message on the form.
In this tutorial we’ve discussed on 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.
- Form Controls in VB.net – Windows Form Controls in VB.net
- Basic Controls in VB.net – What are the Basic Controls in VB.net
- Label Control in VB.net – What is Label Control in VB.net