Chapter 2: Building Visual Basic Applications
Elements of a VB form
A VB form includes Title bar (Icon, Caption, Minimize button, Maximize/Restore Button, Close button, Control menu) and Client area.
Properties of from
Properties
|
Usage
|
Values
|
Name
|
To refer or identify the
form by the code.
|
form1
|
Caption
|
To set the text on title bar.
|
form1
|
Border style
|
To set the style of the form’s
border and appearance.
|
0-none, 1-fixed single,
2-sizable,
3-fixed dialog,
4-fixed tool window,
5-Sizable tool window.
|
Picture
|
To provide a back ground picture.
|
Path name of the picture file.
|
Icon
|
To set the icon on the title bar
and file.
|
Path name of the icon file.
|
Maxbutton
|
To specify the maximize button to
be display or not.
|
True/False
|
MinButton
|
To specify the minimize button to
be display or not.
|
True/False
|
ControlBox
|
To specify the icon to be
Display or not.
|
True/False
|
Windowstate
|
To set the initial state of the form.
|
0-normal, 1-minimized,
2-maximized
|
Events of form
Events
|
Occurrence
|
Code Header
|
Load
|
When form is loaded to memory.
|
Private sub form_Load()
End sub
|
Activate
|
When form becomes the active window.
|
Private sub form_Activate()
End sub
|
Click
|
When user presses and releases
mouse button over the form at one time.
|
Private sub form_Click()
End sub
|
Unload
|
When form is removed from the memory.
|
Private sub form_Unload()
End sub
|
Methods of form
Methods
|
Usage
|
Example
|
Show
|
To display a form
|
Form1.show
|
Hide
|
To hide but not unload a form
|
Form1.hide
|
Print
|
To print a line of text on the form
|
Form1.print “Hello”
|
Common properties of controls
Properties
|
Usage
|
Values
|
Name
|
To refer or identify the control
by the code.
|
List1, command1,
combo1,label1 etc.
|
Appearance
|
To set the display type
|
3D/Flat
|
Backcolor
|
To specify background color
of a control
|
Select a color from palette.
|
Forecolor
|
To specify foreground color
of text in a control
|
Select a color from palette.
|
Font
|
To specify the font settings.
|
Font type, style, size,
effects etc.
|
Caption
|
To set the text on a control.
|
option1, command1, check1,
label1 etc.
|
Text
|
To set the text in a control
|
combo1, text1
|
Top
|
The Y coordinate of the top left
corner of the control.
|
1Twip =1/1440 inch
|
Left
|
The X coordinate of the top left
corner of the control.
|
,,
|
Width
|
To set the width of the control
|
,,
|
Height
|
To set the height of the control
|
,,
|
Enabled
|
To specify the control to be respond
to an user generated event.
|
True/False
|
Visible
|
To specify a control to be
visible or not
|
True/False
|
TabIndex
|
To set the tab order for control
to focus a control
|
Starting from 0
|
TabStop
|
To specify the control to be
accessed by the tab key.
|
True/False
|
Common Events of controls
They classified in to two, Mouse events and Keyboard events.
Mouse Events
Event
|
Occurrence
|
Code Header
|
Click
|
When we presses
and releases mouse button
only ones
|
Private sub Command1_Click()
End sub
|
DblClick
|
When we presses
and releases mouse
button two times quickly.
|
Private sub command1_DblClick()
End sub
|
MouseDown
|
When we presses a
mouse button.
|
Private sub command1_ mouseDown()
End sub
|
MouseUp
|
When we releases a pressed mouse
Button
|
Private sub command1_ MouseUp()
End sub
|
MouseMove
|
When mouse move over an object
|
Private sub command1_ MouseMove()
End sub
|
Keyboard Events
Event
|
Occurrence
|
Code Header
|
KeyPress
|
When we presses and releases
a key on keyboard
|
Private sub command1_KeyPress()
End sub
|
KeyDown
|
When we presses a key
|
Private sub command1_KeyDown()
End sub
|
KeyUp
|
When we releases a pressed key
|
Private sub command1_KeyUp()
End sub
|
Common Methods of controls
Methods
|
Usage
|
Example
|
Move
|
To move a control to a specified location
|
Command1.Move
|
Refresh
|
To repaint a control
|
Form1.Refresh
|
SetFocus
|
To move the focus to a specified control
|
List1.SetFocus
|
Standard Controls in VB
They are Command button, Label, Textbox, Frame, Option button, Check box, Scroll bars, List box, Combo box, Image box, Picture box, Drive list box, Dir list box, File List box and Timer.
Command button
It is used to receive an action that is carried out when the user clicks on it.
Properties
|
Usage
|
Values
|
Default
|
To access through enter key
|
True/False
|
Cancel
|
To choose through Esc key
|
True/False
|
Style
|
To specify the display type
|
Standard/Graphical
|
Label
It is used to display read only text. These texts cannot edit by the user at run time.
Properties
|
Usage
|
Values
|
Alignment
|
To align the text
|
Left, Right, Center
|
Autosize
|
To resize automatically to its content
|
True/False
|
WordWrap
|
To display text in multiple lines (Grow down)
|
True/False
|
Textbox
It is used to display text that can edit by the user. Also it is used to input data from the user to the program.
Properties
|
Usage
|
Values
|
Passwrdchar
|
To set password character
|
Any symbol (*)
|
Multiline
|
To enter text in multiple lines (Address)
|
True/False
|
Maxlength
|
To specify maximum characters to the text box
|
0 to any number
|
Locked
|
To set the text as read only
|
True/False
|
Frame
It helps us to group other controls, so it is a container control.
Option button and Check box
Option button is used to display more than one option from which only one item can select at one time.
Check box is used to display more than one option from which any number of items can select at one time.
Properties
|
Usage
|
Values
|
Value
|
To set the state of control
|
True/False (Option Button)
Unchecked, Checked, Grayed( Check box)
|
Style
|
To set the display type
|
Standard/Graphical (Displayed like button)
|
Scrollbars
They are Hscroll and Vscroll used to navigate the large contents in a control. Also it can use to select or input the values in a range. So it is an input control.
Properties
|
Usage
|
Values
|
Min
|
To set the minimum value
|
Integer (0)
|
Max
|
To set the maximum value
|
Integer(32767)
|
Value
|
It returns the current position value of scroll box
|
Integer (0)
|
Smallchange
|
Returns the value when we click on scroll arrow
|
Integer (1)
|
Largechange
|
Returns the value when we click on scroll box
|
Integer (1)
|
List box
It displays a list of item from which the user can select one or more item. A scroll bar is automatically added if the number of item increases.
Properties
|
Usage
|
Values
|
Style
|
To set the appearance or behavior
|
Standard/Checkbox
|
Sorted
|
To display items in alphabetical order
|
True/False
|
Listcount
|
It gives the number of items
|
Integer value
|
Selected
|
To display an item as selected
|
True/False
|
Listindex
|
It gives the index of selected item
|
Integer (starts from 0)
|
List
|
It holds the item name in the list
|
Item names
|
Methods
|
Usage
|
Syntax
|
Additem
|
Used to add new item with
name and index
|
List1.Additem “Itemname” Index
|
Removeitem
|
Used to remove an
item with index
|
List1.Removeitem “Itemname” Index
|
Clear
|
To remove all items in the list
|
List1.Clear
|
Combo box
It is a combination of list box and text box. It displays a list of item from which the user can select one item. A scroll bar is automatically added if the number of item increases. We can enter the item name portion to select an item from combo box. It uses small space than list box.
Properties
|
Usage
|
Values
|
Style
|
To set the behavior
|
dropdowncombo
simplecombo
dropdownlist
|
Sorted
|
To display items in alphabetical order
|
True/False
|
Listcount
|
It gives the number of items
|
Integer value
|
Listindex
|
It gives the index of selected item
|
Integer (starts from 0)
|
List
|
It holds the item name in the list
|
Item names
|
Locked
|
To set the items as read only
|
True/False
|
Methods
|
Usage
|
Syntax
|
Additem
|
Used to add new item with
name and index
|
Combo1.Additem “Itemname” Index
|
Removeitem
|
Used to remove an item
with index
|
Combo1.Removeitem “Itemname” Index
|
Clear
|
To remove all items in
the combo
|
Combo1.Clear
|
Image box
It helps us to display graphics/images/pictures in the form.
Properties
|
Usage
|
Values
|
Picture
|
To place graphics
|
Path of the file
|
Stretch
|
To determine whether the graphics
resizes to the size of the image box
|
True/False
|
Picture box
It helps us to display and manipulate graphics/images/pictures.
Properties
|
Usage
|
Values
|
Picture
|
To place graphics
|
Path of the file
|
Autosize
|
To determine whether the picture
box resizes to the size of the graphics.
|
True/False
|
File system controls
They are used to accessing file system in hard disk of the computer. They are Drivelistbox, Dirlistbox, Filelistbox.
Drivelistbox
It is used to display and select the drive in the hard disk of computer. (C:/, D:/, E:/ etc.
Properties
|
Usage
|
Values
|
Drive
|
It returns the current selected drive
|
Drive
|
Event
|
Occurrence
|
Syntax
|
Change
|
When we change the drive
|
Private Sub Drive1_Change()
|
Dirlistbox
It is used to displays and selects the folders in the current selected drive in hierarchical way.
Properties
|
Usage
|
Values
|
Path
|
Display the path name of the current folder
|
Pathname
|
Event
|
Occurrence
|
Syntax
|
Change
|
When we change the current folder
|
Private Sub dir1_Change()
|
Filelistbox
It is used to lists and select files in the folder specified by the path property of dirlistbox.
Properties
|
Usage
|
Values
|
Path
|
Display the pathname of the folder whose
files are displayed
|
Pathname
|
Pattern
|
To specify types of files to be displayed
(Extension)
|
*.jpg,*.bmp,*.txt
|
Selected
|
To specify whether a file is selected or not
|
True/False
|
Filename
|
It returns the current file name
|
Name of the file
|
Timer
The timer control can execute some code at regular interval of time. Interval is specified in milliseconds. (1 second =1000 milliseconds). It cannot display at run time
Properties
|
Usage
|
Values
|
Interval
|
To set the interval
|
Milliseconds
|
Event
|
Occurance
|
Syntax
|
Timer
|
It occurs when the time interval enabled
|
Private Sub Timer1_Timer()
|
No comments:
Post a Comment