Basic Controls in VB.net – What are the Basic Controls in VB.net

What is the Basic Controls in VB.net?

Basic Controls in VB.net is a toolbox control on a Visual Basic form used to build an object, a type of user interface element.

In Visual Basic, the shape is actually an object in and of itself.

Basic Control 3 Important Elements in VB.net

  • Properties – These describe the object.
  • Methods – Cause an object to do something.
  • Event – are what happens when an object does something.

Control Properties in VB.net

By adjusting their Control Properties in VB.net, Visual Basic objects can all be moved, scaled, or altered.

A Visual Basic object’s property is a value or feature, such as Fore Color or Caption.

Using the Properties window at design time or program code instructions during execution time, properties can be set.

Object. Property = Value

Object

Object – is the name of the object you’re customizing.

Property

Property – is the characteristic you want to change.

Value

Value – is the new property setting.

Example:

Form1.Caption = "Hello"

Control Methods in VB.net

A Control Method in VB.net is a process developed as a class member that directs an object to take some action.

Methods are used to gain access to or modify an object’s or variable’s properties.

There are mainly two categories of methods you will use in your classes:

  • If you are using a control such as one of those provided by the Toolbox, you can call any of its public methods. The requirements of such a method depend on the class being used.
  • If none of the existing methods can perform your desired task, you can add a method to a class.

For example: the MessageBox control has a method named Show, which is called in the code snippet below

Public Class Form1
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
   Handles Button1.Click
      MessageBox.Show("Hello, World")
   End Sub
End Class

Control Events in VB.net

A Control Event in VB.net is a signal that lets a program know that something significant has happened.

For instance, a form may raise a Click event and invoke an event-handling method in response to a user clicking a control on the form.

Various types of events, such as click, double click, close, load, and resize, are connected to a form.

Following is the default structure of a form Load event handler subroutine.

You can see this code by double-clicking the code which will give you a complete list of all events associated with Form control.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   'event handler code goes here
End Sub

Here, Handles MyBase.Load indicates that the Form1_Load() subroutine handles the Load event. Similar way, you can check the stub code for click, and double click.

If you want to initialize some variables like properties, etc., then you will keep such code inside the Form1_Load() subroutine.

Here, the important point to note is the name of the event handler, which is by default Form1_Load, but you can change this name based on the naming convention you use in your application programming.

Basic Controls in VB.net

A wide range of Basic controls are available in VB.Net, which can be used to build complex user interfaces.

The corresponding control classes for each of these controls define their functionalities.

In the System.Windows.Forms namespace, the control classes are defined.

The following table lists some of the commonly used controls:

#Basic Controls in VB.net
1.Forms Control in VB.net – The container for all the controls that make up the user interface.
2.TextBox Control – It represents a Windows text box control.
3.Label Control – It represents a standard Windows label.
4.Button Control – It represents a Windows button control.
5.ListBox Control – It represents a Windows control to display a list of items.
6.ComboBox Control – It represents a Windows combo box control.
7.RadioButton Control – It enables the user to select a single option from a group of choices when paired with other RadioButton controls.
8.CheckBox Control – It represents a Windows CheckBox.
9.PictureBox Control – It represents a Windows picture box control for displaying an image.
10.ProgressBar Control – It represents a Windows progress bar control.
11.ScrollBar Control – It Implements the basic functionality of a scroll bar control.
12.DateTimePicker Control – It represents a Windows control that allows the user to select a date and a time and to display the date and time with a specified format.
13.TreeView Control – It displays a hierarchical collection of labeled items, each represented by a TreeNode.
14.ListView Control – It represents a Windows list view control, which displays a collection of items that can be displayed using one of four different views.
Basic Controls

Conclusion

Controls in VB.net are one of the most useful features of VB.net in designing and creating Forms.

Mastering the controls, their properties, events, and their methods helps a lot in creating intuitive and user-friendly User Experiences.


Leave a Comment