Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

VB.Net - Basic control


May 13, 2021 vb.net


Table of contents


An object is a user interface element created on a Visual Basic form by using toolbox controls. I n fact, in Visual Basic, the form itself is an object. E ach Visual Basic control consists of three important elements:

  • Properties: Describes the properties of an object,

  • Methods: Methods cause objects to do something,

  • Events: Events are events that happen when an object does something.


Control the properties

All Visual Basic objects can be moved, resized, or customized by setting their properties. A property is a value or attribute held by a Visual Basic object, such as Caption or Fore Color.

Properties can be set at design time by using a property window or at runtime by using statements in program code.

Object. Property = Value

  • Object is the name of the object you're customizing. Object is the name of the object you want to customize.

  • Property is the characteristic you want to change. The property is the attribute that you want to change.

  • Value is the new property setting. Value is the new property setting.


For example

Form1.Caption = "Hello"

You can use the property window to set any form property. M ost properties can be set or read during application execution. Y ou can refer to the complete list of properties in the Microsoft documentation related to the different controls and restrictions that apply to them.


The control method

Methods are procedures created as members of classes that make objects do something. M ethod is used to access or manipulate the properties of an object or variable. There are two main types of methods that you will use in your class:


1. If you use one of the controls provided by the toolbox, you can call any of its common methods. The requirements for this approach depend on the class you are using.

2. If you don't have an existing method to perform the required tasks, you can add a method to the class.


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

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 the event

An event is a signal that an important event has occurred in the application. F or example, when a user clicks a control on a form, the form can raise a Click event and call the procedure that handles the event. There are various types of events associated with the form, such as clicking, double-clicking, closing, loading, resizing, and so on.

The following is the default structure of the formLoad event handler sub-routine. You can view this code by double-clicking it, which gives you a complete list of all the events associated with the 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 means that Form1_Load () sub-routine handles load events. S imilarly, you can check the sting code by clicking and double-clicking. I f you want to initialize some variables, such as properties, etc., then you save Form1_Load in a sub-program. H ere, the important thing is the name of the event handler, which is Form1_Load by default, but you can change it based on the naming conventions you use in application programming.


Basic control

Vb. N et provides a variety of controls to help you create a rich user interface. T he functions of all these controls are defined in the appropriate control class. Control classes are defined in the System.Windows.Forms namespace.

The following table lists some commonly used controls:

S.N. Widgets and instructions
1

Form form

The container for all the controls that make up the user interface.

The container used to make up all the controls in the user interface.

2

TextBox text box

It represents a Windows text box control.

It represents a Windows text box control.

3

Label label

It represents a standard Windows label.

It represents a standard Windows label.

4

Button button

It represents a Windows button control.

It represents a Windows button control.

5

ListBox list box

It represents a Windows control to display a list of items.

It represents a Windows control that displays a list of items.

6

ComboBox combo box

It represents a Windows combo box control.

It represents a Windows combo box control.

7

RadioButton radio button

It enables the user to select a single option from a group of choices when paired with other RadioButton controls.

It enables users to select an option from a set of options when paired with other RadioButton controls.

8

CheckBox check box

It represents a Windows CheckBox.

It represents a Windows check box.

9

PictureBox picture box

It represents a Windows picture box control for displaying an image.

It represents the Windows screen box control used to display the image.

10

ProgressBar progress bar

It represents a Windows progress bar control.

It represents a Windows progress bar control.

11

ScrollBar scroll bar

It Implements the basic functionality of a scroll bar control.

It implements the basic functionality of scroll bar controls.

12

DateTimePicker date input box

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.

It represents a Windows control that allows the user to select a date and time and display the date and time in the specified format.

13

TreeView treemap

It displays a hierarchical collection of labeled items, each represented by a TreeNode.

It displays a hierarchical collection of label items, each represented by a tree node.

14

The ListView list is displayed

It represents a Windows list view control, which displays a collection of items that can be displayed using one of four different views.

It represents a Windows list view control that displays a collection of items that can be displayed using one of four different views.