VB.NET Form Controls

A Form is used in VB.NET to create a form-based or window-based application. Using the form, we can build a attractive user interface. It is like a container for holding different control that allows the user to interact with an application. The controls are an object in a form such as buttons, Textboxes, Textarea, labels, etc. to perform some action. However, we can add any control to the runtime by creating an instance of it.

A Form uses a System.Windows.Form namespace, and it has a wide family of controls that add both forms and functions in a Window-based user interface.

VB.NET Form Properties

The following are the most important list of properties related to a form. And these properties can be set or read while the application is being executed.

PropertiesDescription
BackColorIt is used to set the background color for the form.
BackgroundImageIt is used to set the background image of the form.
CursorIt is used to set the cursor image when it hovers over the form.
AllowDropUsing the AllowDrop control in a form, it allows whether to drag and drop on the form.
FontIt is used to get or set the font used in a form.
LockedIt determines whether the form is locked or not.
FormBorderStyleIt is used to set or get border style in a form.
TextIt is used to set the title for a form window.
MinimizeBoxMinimizeBox It is used to display the minimum option on the title bar of the form.
IsMDIChildIt is used to authenticate whether a form is a container of a Multiple Document Interface (MDI) child form.
AutoscrollIt allows whether to enable auto-scrolling in a form.
MaximizeBoxIt is used to display the maximum option on the title bar of the form.
MaximumSizeIt is used to set the maximum height and width of the form.
LanguageIt is used to specifies the localized language in a form.
AcceptButtonIt is used to set the form button if the enter key is pressed.
Top, LeftIt is used to set the top-left corner coordinates of the form in pixel.
NameIt is used to define the name of the form.
MinimumSizeIt is used to set the minimum height and width of the form.
EnabledIt uses the True or False value to enable mouse or keyboard events in the form.
TopMostIt uses a Boolean value that represents whether you want to put the window form on top of the other form. By default, it is False.

Form Events

The following are the most important list of events related to a form.

EventsDescription
ActivatedAn activated event is found when the user or program activates the form.
ClickA click event is active when the form is clicked.
ClosedA closed event is found before closing the form.
ClosingIt exists when a form is closing.
DoubleClickDoubleClick
The DoubleClick event is activated when a user double clicks on the form.
DragDropA DragDrop event is activated when a drag and drop operation is performed.
MouseDownA MouseDown event is activated when the mouse pointer is on the form, and the mouse button is pressed.
GotFocusA GotFocus event is activated when the form control receives a focus.
HelpButtonClickedIt is activated when a user clicked on the help button.
KeyDownA KeyDown event is activated when a key is pressed while focussing on the form.
KeyUpA KeyUp event is activated when a key is released while focusing on the form.
LoadThe load event is used to load a form before it is first displayed.
LostFocusIt is activated when the form loses focus.
MouseEnterA MouseEnter event is activated when the mouse pointer enters the form.
MouseHoverA MouseHover event is activated when the mouse pointer put on the form.
MouseLeaveA MouseLeave event is activated when the mouse pointer leaves the form surface.
ShownIt is activated whenever the form is displayed for the first time.
ScrollA Scroll event is activated when a form is scrolled through a user or code.
ResizeA Resize event is activated when a form is resized.
MoveA Move event is activated when a form is moved.

For creating a Windows Forms application in VB.NET, we need to follow the following steps in Microsoft Visual Studio.

  1. GoTo File Menu.
  2. Click on New Project.
  3. Click on Windows Forms App or Application

And finally, click on the 'Create' button to create your project, and then, it displays the following window form with a name Form1.

VB.NET Form Controls

Now create a simple program of Windows form control in VB.NET.

Form1.vb

Output:

VB.NET Form Controls

Now enter the following details in the form:

VB.NET Form Controls

After filling all the details, click on the Submit button. After that, it shows the following Output:

VB.NET Form Controls




Latest Courses