VB Forms
Form modules are the foundation of most
visual basic applications. Inside form module, you can define the following
1. Event procedures
2. Form based declarations of
variables and constants
Variables, constants several form
events that you may need to consider are as follows
-
Initialize : event is called before the form is loaded
-
Load event : is called after the initialize event
-
Got focus event is called after that, It is called when user
click the form or you load the form through code
-
Resize event is called when either user change the size of
the form
-
Paint event is called when the form is redrawn
The most important properties of the
form are listed in the following
Property
name objective
Name used to represent name of
form
Caption string appear for the title of form
Back
color back ground color for form
Fore
color Color of text written on form
Font Font style, type and size
Enabled Enable or disable
Min
button =true
Max
button the minimize and maximize
buttons are
Enabled
Hide To hide the form
Show the show the form
Icon change the icon on title bar of form
Private
sub form_load
Form1.backcolor
= QBcolor(12)
End
sub
Integrated Development
Environment (IDE )
-
One of the most significant changes
in visual basic is the integrated development environment (IDE)
-
IDE is the term commonly used in the
programming world to describe the interface and environment that we use to create
new applications
-
It is called integrated because we
can access virtually all of the development tools that we need from one screen
called an interface.
-
The IDE is also commonly referred to
as the design environment or the program.
Menu / Tool bar: This is the
only element of the IDE which is always visible. You use it to select which
other IDE elements to view and to add forms or controls to your project.
Tool box: The tool box is
simply a library of controls which you can place on your application. Once you
have placed all the controls you need onto your applications forms. You can
hide the tool box to make room for working in the other elements on the IDE.
Project window
This is simply a list of all the forms
which make up your vb project. There are several kinds of forms.
Property window
Most VB applications allow you to
enter parameters which define how these controls work In Vb these parameters
are called properties.
Forms: you add these to your
VB application as they are needed. They are the windows which hold the various controls
which make up your application.
Code window
Like, it’s name implies, this is where
you type in the code that VB executes. Notice that the heading of the window
indicates with which event the code is executed.
Controls in Visual Basic
Command
button
Command button appears in almost every
program. Command buttons determines when the user wants to do something such as
exit the application, you will perform these tasks to add a command button to
an application.
1. Locate
the size of the command button on the form
2.change the
command button’s name and caption properties.
3.Add code
to the command button’s click event procedure.
Although the command button control
supports dozens of properties, Although command button controls support over
dozen events.
Property description
Back
color specified the command
button’s
Background color
Caption hold the text that appears on the
command
Font produces a font dialog box in which
you can set
the caption’s font name,
style and size
height holds the height of the command button
mouse
pointer determines the shape of the
mouse
cursor when the user moves
the mouse over
the command button
tool
tip holds the text that appears as a
tool tip at
run time .
Sub
command1_click()
Dim a, b as
integer
a = inputbox
(“enter a”)
b = inputbox
(“enter b”)
if ( a >
b ) then
msgbox (“ a is biggest”)
else
msgbox (“ b
is biggest”)
end if
end sub
Text Box
The text box is the standard control
for accepting input from the user as well as to display the output. It can
handle string and numeric data but not
images or pictures.
Private sub command1_click()
Dim sum as integer
Sum = val(text1.text) +
val(text2.text)
Msgbox(sum)
End sub
The picture box
The picture box is one of the control’s
that is used to handle graphics. You can load a picture at design phase by
clicking on the picture items in the properties window you can also load the
picture at run time using the load picture method.
Picture1.picture =
loadpicture(“c:\windows\mku.jpg”)
The image control
He image control is another control that
handles images and pictures. It functions almost identically to the picture
box. However, there is one major difference the image is an image but is stretchable, which means it can be
resized. This feature is not available in the picture box. Similar to the
picture box, it can also use the load picture
The list box
The function of the list box is to
present a list of items where the user can click and select the items from the
list. In order to add items to the list, we can use the additem method.
Privare sub Form_load()
List1.additem(“sunday”)
List1.additem(“Monday”)
List1.additem(“Tuesday”)
List1.additem(“Wednesday”)
List1.additem(“Thursday”)
List1.additem(“Friday”)
List1.additem(“Saturday”)
End sub
The check box
The check box control lets the user
selects or unselects an option. When the check box is checked, its value is set
to 1 and when it is unchecked , the value is set to 0. You can include the
statements check1.value =0 to unmark the
check box , as well as, use them to initiate certain actions.
Option button
The option button control also lets
the user selects one of the choices. However , two or more option buttons must
work together because as one of the option buttons is selected, the other
option button will be unselected. In fact only one option box can be selected
at one time and when it is unselected, its value is set to false.
Sub command1_click()
If option1.value = true then
Form1.backcolor =vbred
Else if option2.value = true
then
Form1.backcolor = vbBlue
Else
Form1.backcolor = vbGreen
End if
End sub
DirList box
The dirlist box means the directory
list box. It is for displaying or list of directories or folders in a selected
drive. When you place this control into the form and run the program. You will
be able to select different directories from a selected drive in your computer.
DriveList box
The drive list box is for displaying
a list of drives available in your computer. When you place this control into
the form and run the program
The File List box
You can coordinate the drive list
box, the directory list box and the file list box to search for the files you
want
Msgbox and Input box
The msgbox
function displays a message box and waits for the user to click a button and
then an action is performed based on the button clicked by the user.
Msgbox(prompt,[button],[title])
Prompt –a string that is displayed as a message in the
dialog box.
Buttons – specifies the type of buttons to display
Title: title bar of the dialog box
The buttons
parameter can take any of the following buttons
0 – displays ok button only
1 – Displays ok and cancel button
2- Displays abort, retry and ignore buttons
3-Displays yes, no and cancel buttons
4- Displays yes and no buttons
5- Displays retry and cancel buttons
16 vbcritical-displays critical message icon
32 vbquestion – displays warning query icon
48 vbExclamation – displays warning message icon
64
vbinformation information message icon
The msgbox
function can return one of the following values which can be used to identify
the button the user has clicked in the msgbox.
1 ok was clicked
2 cancel was clicked
3 abort was clicked
4 retry was clicked
5 Ignore was clicked
6 yes was clicked
7 no was clicked
Sub command1_click()
Msgbox(“welcome”)
Int a =msgbox(“Do you like blue color?”,3,”choose
options”)
Msgbox(“the value of a is “ &a)
End sub
A
message box is special type of visual basic window in which you can display a
message to the user. You can display message, an optional icon, a title bar
caption and command button in a msgbox.
Input
box
The input box function prompts the user
to enter values, after entering the values, if the user clicks the OK button or
presses enter on the keyboard. The input box function will return the text in
the text box. If the user clicks the cancel button the function will return an
empty.
Syntax
Inputbox
( prompt [.title] [, default])
Prompt
– A string that is displayed as a
message in the dialog box
Title
– a string expression displayed in the title bar of the dialog box
Default
– A default text in the text box that the user would like to be displayed
Sub
command1_click()
Dim
l as Double
Dim
w as Double
Dim
area as Double
l=
inputbox (“enter length”)
w=Inputbox
(“enter width”)
area
= l * w
msgbox(area)
end
sub
The
input box () function is used to take the input from the user at run time.
General syntax
Inputbox(prompt,
title, default, xpos,ypos,helpfile,context)
Prompt
– the message in the dialog box
Title
– the title bar of the dialog box
Default- string to be displayed in the text box on
loading.
Xpos
– the distance from the top of the screen to the top of the dialog box
When you use input box() function, the
program will show a simple window with a question for the user. The window will
also have a place for the user to type in their answer, an OK button and a
“cancel” button. If the user clicks the OK button any information typed into
the text box will be sent back to your program. If the user clicks “cancel” key
will return to your program without sending any information.
Private
sub Command1_click()
Dim
city as String
City
= input box(“enter your city”, ”city question”)
Msgbox(city)l
End
sub
Sub
command2_click()
Dim
a as integer
Dim
b as integer
Dim
c as integer
a
= inputbox (“enter number1”)
b=inputbox(“enter
number2”)
c=
a + b
msgbox(c)
end
sub
Font
Dialog box and print Dialog box
Dialog box consist of a
title bar, an optional main instruction, various controls in the content area,
and command buttons. The font dialog box lets the user choose attributes for a
logical font, such as font family and associated font style, size, effects.
This dialog box can display the fonts supported by either printer or screen.
Font bold: Bold is used to highlight the
text and capture the reader’s attention
Font
Italic: Letters slanted slightly to the right
Font
strike thru : It implies the text is wrong
Font
underline: Commonly used to help draw attention to text
Font
name: Defining font style for text
Font
size: refers to the height of a character
Each
dialog box allows user to select his custom font setting like font name, font
size, font color, font style, strike thru etc. To display the font display on
the screen use show font method of the common dialog object.
Sub
command1_click()
Dim
i as integer
List1.addItem
“times new roman”
List1.additem
“arial”
List1.additem
“sans serif”
List1.additem
“ minion pro”
List2.addItem “regular”
List2.additem
“ bold”
List2.additem “Italic”
List2.additem
“ bold italic”
For
i= 8 to 25 step 2
List3.additem
i
Next
i
End
sub
Print dialog
The print dialog control lets the user
to print documents by selecting a printer and choosing which sections of the
document to print. Allow you to specify the printer. If you don’t select a
printer visual basic will print to the windows default printer.
Name
– displays a list of available printers
Status
– displays the status of the printer and whether it is ready to print.
Type
– displays the type of printer
Print dialog lets users select which
printer to use for a print job and specify options for the print process. These
options include specifying all pages, a range of pages, or the selection to
print. There’s also an option to specify the number of copies to be printed, as
well as an option to print to a file.
The print dialog displays a dialog box that
allows the user to choose printer settings for a document. The user can specify
the printer to user, range of pages to print, and the number of copies.
The print dialog box allows a user to
select a printer if more than one is available. The user can decide either to
print the whole document, to print a range of pages, or to print a portion of
the document that was previously selected. The user can also decide on the
number of copies to print from the document the range specified or the selected
portion. Furthermore, the user can access the particular characteristics of the
selected printer and specify how the printer should perform the job. If the
selected printer can print in color and the document is in color but the user
wants to print in black and white, he or she can specify this using the
properties button.
TOOL BOX
Control |
Description |
Pointer |
Provides a way to move and resize the controls form |
Picture Box |
Displays icons/bitmaps and metafiles. It displays text or acts as a
visual container for other controls. |
TextBox |
Used to display message and enter text. |
Frame |
Serves as a visual and functional container for controls |
Command Button |
Used to carry out the specified action when the user chooses it. |
Check Box |
Displays a True/False or Yes/No option. |
Option Button |
Option Button control which is a part of an option group allows the
user to select only one option even it displays multiple choices. |
List Box |
Displays a list of items from which a user can select one. |
Combo Box |
Contains a Text Box and a List Box. This allows the user to select an
item from the dropdown List Box, or to type in a selection in the Text Box. |
HScroll Bar and VScroll Bar |
These controls allow the user to select a value within the specified
range of values |
Timer |
Executes the timer events at specified intervals of time |
Drive List Box |
Displays the valid disk drives and allows the user to select one of
them. |
Dir List Box |
Allows the user to select the directories and paths, which are
displayed. |
File List Box |
Displays a set of files from which a user can select the desired one. |
Shape |
Used to add shape (rectangle, square or circle) to a Form |
Line |
Used to draw straight line to the Form |
Image |
used to display images such as icons, bitmaps and metafiles. But less
capability than the Picture Box |
Data |
Enables the use to connect to an existing database and display
information from it. |
OLE |
Used to link or embed an object, display and manipulate data from
other windows based applications. |
Label |
Displays a text that the user cannot modify or interact with. |
No comments:
Post a Comment