VB.Net - Basic Controls (2024)

VB.Net - Basic Controls (1)

  • VB.Net Basic Tutorial
  • VB.Net - Home
  • VB.Net - Overview
  • VB.Net - Environment Setup
  • VB.Net - Program Structure
  • VB.Net - Basic Syntax
  • VB.Net - Data Types
  • VB.Net - Variables
  • VB.Net - Constants
  • VB.Net - Modifiers
  • VB.Net - Statements
  • VB.Net - Directives
  • VB.Net - Operators
  • VB.Net - Decision Making
  • VB.Net - Loops
  • VB.Net - Strings
  • VB.Net - Arrays
  • VB.Net - Collections
  • VB.Net - Functions
  • VB.Net - Subs
  • VB.Net - Exception Handling
  • VB.Net - File Handling
  • VB.Net - Basic Controls
  • VB.Net - Dialog Boxes
  • VB.Net - Advanced Forms
  • VB.Net - Event Handling
  • VB.Net Advanced Tutorial
  • VB.Net - Regular Expressions
  • VB.Net - Database Access
  • VB.Net - Excel Sheet
  • VB.Net - Send Email
  • VB.Net - XML Processing
  • VB.Net - Web Programming
  • VB.Net Useful Resources
  • VB.Net - Quick Guide
  • VB.Net - Useful Resources
  • VB.Net - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });

An object is a type of user interface element you create on a Visual Basic form by using a toolbox control. In fact, in Visual Basic, the form itself is an object. Every Visual Basic control consists of three important elements −

  • Properties which describe the object,

  • Methods cause an object to do something and

  • Events are what happens when an object does something.

Control Properties

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

Properties can be set at design time by using the Properties window or at run time by using statements in the program code.

Object. Property = Value

Where

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

  • Property is the characteristic you want to change.

  • Value is the new property setting.

For example,

Form1.Caption = "Hello"

You can set any of the form properties using Properties Window. Most of the properties can be set or read during application execution. You can refer to Microsoft documentation for a complete list of properties associated with different controls and restrictions applied to them.

Control Methods

A method is a procedure created as a member of a class and they cause an object to do something. Methods are used to access or manipulate the characteristics of an object or a variable. 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 SubEnd Class

Control Events

An event is a signal that informs an application that something important has occurred. For example, when a user clicks a control on a form, the form can raise a Click event and call a procedure that handles the event. There are various types of events associated with a Form like click, double click, close, load, resize, etc.

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 the all events associated with Form control −

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

Here, Handles MyBase.Load indicates that Form1_Load() subroutine handles Load event. Similar way, you can check stub code for click, double click. If you want to initialize some variables like properties, etc., then you will keep such code inside Form1_Load() subroutine. Here, 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 your naming convention you use in your application programming.

Basic Controls

VB.Net provides a huge variety of controls that help you to create rich user interface. Functionalities of all these controls are defined in the respective control classes. The control classes are defined in the System.Windows.Forms namespace.

The following table lists some of the commonly used controls −

Sr.No.Widget & Description
1

Forms

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

2

TextBox

It represents a Windows text box control.

3

Label

It represents a standard Windows label.

4

Button

It represents a Windows button control.

5

ListBox

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

6

ComboBox

It represents a Windows combo box control.

7

RadioButton

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

8

CheckBox

It represents a Windows CheckBox.

9

PictureBox

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

10

ProgressBar

It represents a Windows progress bar control.

11

ScrollBar

It Implements the basic functionality of a scroll bar control.

12

DateTimePicker

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

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

14

ListView

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

Advertisem*nts

';adpushup.triggerAd(ad_id); });

VB.Net - Basic Controls (2024)

FAQs

What are the 8 basic controls in Visual Basic? ›

Visual Basic controls
  • Text Box.
  • Label.
  • Button.
  • ListBox.
  • Combo Box.
  • Radio Button.
  • Checkbox.
  • PictureBox.
Feb 10, 2022

How many default controls are available in VB answer? ›

The three basic VB controls are the Label, Textbox, and Button; these are the controls we will be working with for this program.

What are the three important elements every VB control consists of? ›

Every Visual Basic control consists of three important elements: Properties which describe the object, Methods cause an object to do something and Events are what happens when an object does something.

How to create controls in VB? ›

From the VB main menu, click Project, then Add User Control. This gives you a form design environment almost identical to the one you use for building standard Windows applications. Add the components and code for your control and customize the properties you need.

What is VB control structure? ›

Control structures allow you to regulate the flow of your program's execution. Using control structures, you can write Visual Basic code that makes decisions or that repeats actions.

How many types of control are there in VB? ›

The control classes are defined in the System. Windows. Forms namespace.
Sr.No.Widget & Description
3Label It represents a standard Windows label.
4Button It represents a Windows button control.
5ListBox It represents a Windows control to display a list of items.
6ComboBox It represents a Windows combo box control.
10 more rows

What is a Visual Basic short answer? ›

Visual Basic (VB) is an event-driven programming language and environment from Microsoft that provides a graphical user interface (GUI) which allows programmers to modify code by simply dragging and dropping objects and defining their behavior and appearance.

What is the difference between object and control in VB? ›

Controls are a subset of objects that are generally OCX files that are dropped onto a form.

What is the ToolBox in Visual Basic? ›

The toolbar containing the Visual Basic controls like textbox, label, commandbutton, etc. is called ToolBox in vb. You can drag & drop the controls from toolbox on a vb form.

What are the 3 types of VB modules? ›

Code in Visual Basic is stored in the form of modules. The three kind of modules are Form Modules, Standard Modules and Class Modules.

What are the two major components of Visual Basic? ›

The Visual Basic language is an object-oriented language that consists of two fundamental parts : – The Visual part -- consists of a set of objects. – The Language (code) part -- consists of a high-level procedural programming language.

How to create a .Net control? ›

Creating.NET Controls in a.NET Container
  1. Add a.NET container to the front panel window.
  2. Right-click the front panel window.NET container and select Insert.NET Control from the shortcut menu to display the Select.NET Control dialog box.
  3. Select an assembly from the Assembly pull-down menu.

Which control is used to execute any VB procedure? ›

Answer: Run > Run Macro control is used to execute any macro vb procedure.

How to use user control in Visual Basic? ›

The following steps demonstrate how to add a user control to your project:
  1. In Visual Studio, find the Project Explorer pane. Right-click on the project and choose Add > User Control (Windows Forms).
  2. In the Name box, type a name for your user control. Visual Studio provides a default and unique name that you may use.
Apr 19, 2024

What are the basic controls in VB net? ›

VB.NET Controls are the pillars that help in creating GUI Based Applications in VB.Net quickly and easily. Windows Forms contains various controls that you can add to forms: controls that display text boxes, buttons, drop-down boxes, radio buttons, and even Web pages.

What are common controls in VB net? ›

Common controls
  • Scroll bars.
  • Input fields.
  • Combo boxes and drop-down lists.
  • Check boxes.
  • Radio buttons.
  • Group frames.
  • Text controls.
  • Buttons and hyperlinks.
Mar 9, 2023

What are the commands in Visual Basic? ›

Contents
  • 1.1 Asc.
  • 1.2 Chr.
  • 1.3 Len.
  • 1.4 Left.
  • 1.5 Right.
  • 1.6 Mid (Function)
  • 1.7 Mid (Statement)
  • 1.8 Trim.

Top Articles
Latest Posts
Article information

Author: Amb. Frankie Simonis

Last Updated:

Views: 6442

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Amb. Frankie Simonis

Birthday: 1998-02-19

Address: 64841 Delmar Isle, North Wiley, OR 74073

Phone: +17844167847676

Job: Forward IT Agent

Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.