Functions and Controls Of Vb

Controls/ Objects

In VB, a program is started by drawing the user interface (the part of the program a user will see) on a form (the rectangular area with the grid marks in the center of the IDE). All the controls you can place on a form are in the toolbox, on the left side of the IDE. Controls you place on a form and the form itself are called objects.
Examples of objects:

VB   5


• form – a windows screen
• button
• label – user can not change during run time
• text Box – user can change during run time
• horizontal scroll bar
• picture Box
The Toolbox contains the following standard controls:
• Picture Box
• Label
• Text Box
• Button
• Group Box
• Check Box
• Radio Button
• Combo Box
• List Box
• Horizontal Scroll Bar
• Vertical Scroll Bar
• Timer
When placing several objects on a form, use the commands on the Format menu to place, size, and align the objects. First, drag the mouse around the objects to select them. Using the commands on the Format menu, you can then align or size the objects as necessary. Object properties can generally be set at either design time or run time

Controls/Objects
In VB, a program is started by drawing the user interface (the part of the program a user will see) on a form (the rectangular area with the grid marks in the center of the IDE). All the controls you can place on a form are in the toolbox, on the left side of the IDE. Controls you place on a form and the form itself are called objects.
Examples of objects:
• form – a windows screen
• button
• label – user can not change during run time
• text Box – user can change during run time
• horizontal scroll bar
• picture Box
The Toolbox contains the following standard controls:
• Picture Box
• Label
• Text Box
• Button
• Group Box
• Check Box
• Radio Button
• Combo Box
• List Box
• Horizontal Scroll Bar
• Vertical Scroll Bar
• Timer
When placing several objects on a form, use the commands on the Format menu to place, size, and align the objects. First, drag the mouse around the objects to select them. Using the commands on the Format menu, you can then align or size the objects as necessary. Object properties can generally be set at either design time or run time

In VB, a program is started by drawing the user interface (the part of the program a user will see) on a form (the rectangular area with the grid marks in the center of the IDE). All the controls you can place on a form are in the toolbox, on the left side of the IDE. Controls you place on a form and the form itself are called objects.
Examples of objects:
• form – a windows screen
• button
• label – user can not change during run time
• text Box – user can change during run time
• horizontal scroll bar
• picture Box
The Toolbox contains the following standard controls:
• Picture Box
• Label
• Text Box
• Button
• Group Box
• Check Box
• Radio Button
• Combo Box
• List Box
• Horizontal Scroll Bar
• Vertical Scroll Bar
• Timer
When placing several objects on a form, use the commands on the Format menu to place, size, and align the objects. First, drag the mouse around the objects to select them. Using the commands on the Format menu, you can then align or size the objects as necessary. Object properties can generally be set at either design time or run time

Label Control
A label is a graphical control used to display text. The user cannot edit the text in a label. The most common use for a Label control is to identify controls that do not have a Caption property, such as the TextBox control. You can also use the Label control to display text such as status messages and other program information.
TextBox Control
You use a TextBox control to obtain information from the user or to display information provided by the application. Unlike information displayed in a label, the user can change information displayed in a text box.
TextBox objects have a ‘ReadOnly’ property, that when set to ‘true’ does not allow the user to type into the textbox.
Button Control:
A Button performs a task when the user clicks the button. You use a Button control to begin, interrupt, or end a process. When clicked, a command button appears to be pushed in and so is sometimes called a push button. The most common event for a Button control is the Click event.
Object Naming Conventions
All objects you place on a form must be given a name, in this course. An object’s name is used to refer to the object in your program code. You can assign any name to an object, but it is a good idea to adopt a naming convention and use it consistently throughout your programs.
The following table lists the standard naming conventions used in Visual Basic. Adopting these conventions makes it easier for others familiar with the standard naming conventions to understand your code.

Suggested Prefixes for Controls
Control Type Prefix Example
Check box chk chk Read Only
Combo box, drop-down list box cbo cbo English
Button btn btn Exit
Form frm frm Entry
Horizontal scroll bar hsb hsb Volume
Label lbl lbl Help Message
List box lst lst Policy Codes
Menu mnu mnu File Open
Radio button rad rad Gender
Picture box pic pic VGA
Text box txt txt Last Name
Timer tmr tmr Alarm
Vertical scroll bar vsb vsb Rate

Properties

Properties define the appearance and behavior of objects. Text, Font, and Name are common examples of properties. Properties are the attributes you set or retrieve. Each object has a long list of properties. These properties are very important to making the screen look right and to making the program act right.
Setting Properties at Design-Time:
Design-time is the time when you are laying out your form and writing your program code. Most properties of any object may be set at design-time. When an object on the form is selected, the properties for the object are displayed on the right-side of the IDE. To change or set a property, simply type your desired change in the area next to the property name.

Examples of Label properties:
o text – the text that appears on the screen
o name – the name of the object
NB: We will never leave the names – Label1, Label2, etc – because these are not meaningful names and will be confusing.
We will use the suggested prefix (see above) and meaningful names so that others familiar with the standard naming conventions will more easily understand your code. Eg. change the name of Label1 to lblTitle
o font – controls the font, size, style (bold italics)
o forecolor – controls the colour of letters. The properties window shows a coded number (more later on the hex number)
o back color – controls the background color of the label (a box)
o visible – controls whether the label is visible or not (True or False)
Examples of Form properties:
• back color – controls the background color of the whole screen
• text – the text that appears in the form’s title bar
• window state – controls how big the window is when the program is run
0 Normal 1 Minimized 2 Maximized (best)
• name – the name of the form
eg. change Form1 to frmTitlescreen
• FormBorderStyle – controls the appearance of the form=s border
also determines whether the user can resize the form
you set the BorderStyle property at design time
you cannot change the BorderStyle property at run time
• Size – to set the size of a form
Changing Object Properties during Run-Time
When the user is running the program, this is called run-time. Any property of any object can be changed during run-time. The general form of commands to change object properties is:
objectname.property=value
Examples:
• lblQuestion.visible = False (makes lblQuestion invisible)
• lblAnswer.ForeColor = &H000000FF& (changes the foreground color of the label to red. &H – hexadecimal number (base 16 – 0 1 2 3 4 5 6 7 8 9 A B C D E F). To figure this number out, manually change the property and carefully record the number. The hexadecimal code numbers are built based on so much Red Green and Blue)

]]>

admin

Leave a Reply

Your email address will not be published. Required fields are marked *