VB - 2 Unit
VB - 2 Unit
VB - 2 Unit
Pointer
Picture Box
Timer
Shape Control
Line Control
Image Control
Data Control
OLE
The tool box is one of the window in the visual basic desktop. It contains the standard
controls.
The standard controls found in the tool box are Picture Box, Labels, textbox Frames,
Command Button, Check Box, Option Button, Combo Box, List Box, Horizontal scroll bars, Vertical
scroll bar, Timer, Drive List box, Directory Listbox, File listbox, Shape. Line, Image data and OLE.
Apart from these standard controls, there are many other controls like DB combo, Dblist etc..
These advanced controls can be added to the toolbox in two ways.
• By selecting the components command from the project menu.
• By right clicking the mouse on the toolbox and (hen selecting the components command.
There are various components in the list we choose whatever we want by clicking on the text
box listed on the side of each one and finally finish by ok button to be appeared on the tool box.
CREATING CONTROLS
The objects available in the toolbox are called controls. Using these controls, the user can
interact with the application program and control the application program.
We can always get a control on a form by double clicking on its icon in the toolbox. This
gives you control in its default size and shape in the size of the form. This is certainly one way to
proceed.
Another way to bring the control to the form is by clicking the selected tool on the toolbox,
then move the mouse pointer to the form and start drawing through click to the required size of the
user
Each control has eight little boxes, called sizing handles. We can use these handles to move
and resize a control after you have created it.
We can use Cut, Copy, and Paste on the controls, Moving of control from one place to other
place of the form is possible. There are possible for locking the controls. That is once placed cannot be
moved when the control is not need we can also Delete the controls.
Mouse pointer
Sets different mouse pointer from the available pointers.
ACCESS KEYS:
Many window applications allow using ALT and other keys as a shortcut key called “The
Access Key”, to quickly activate a control or to a menu item itself. These access keys are underlined
in the caption of the control or name of the menu item.
VB makes it easy to set up an access key for any object that has a caption property. When you
set the caption, all you have to do is place an ampersand (&) in front of the letter you want td make it
as an Access Key.
Although it is possible to have the same access key for more than one control on a form, doing
so is unusual. The focus moves to the next control with the same access key. but that control is not
activated until you click the mouse or press the spacebar.
THE GRID
The grid is important for accurately positioning of controls. In order to control the grid, choose
tools/option and then go to the general page on the options dialog box.
This property lets you to change the font styles that are being selected by the users.
Eg
RichTextBox1.SelFontName = "Times New Roman"
SelFontSize
This property lets you to change the font size of the currently selected text, the syntax is
RichTextBox1.SelFontSize = 14
IMAGE CONTROL
Image controls can be used to display icons or pictures with the program such as Microsoft
Paintbrush. They can hold window BMP, GIF metafiles or JPEG. JPEG format is also the common
format used by most digital cameras. Since the image controls respond to the click event, you can use
these images to substitute for the command buttons.
You can load a picture into an image control by resulting the value of the
picture property. If you choose the picture property for the image control, this opens
up a dialog box that lets you choose what image file to load.
You can also reset the picture property directly by copying an image from a graphics program to the
windows clipboard and then using the Copy command on the edit menu to part the image into the
image control. VB will attach the graphics to the project when you save it. Finally, you can change
this property.
Example:
The
default message box is VBOK only, which the user can click the OK button and end the message box.
The user can choose his own message box, either by specifying the value of the message box or by
giving the full name of the message box. The table below summarizes its information
You combine three different groups of built-in integer constants to specify the kind of
message box. The first number controls what kind of buttons appears. The following table summarizes
this information.
vbOK 1 OK
vbCancel 2 Cancel
vbAbort 3 Abort
vbRetry 4 Retry
vbIgnore 5 Ignore
vbYes 6 Yes
vbNo 7 No
vbApplicationModal 0 Application modal; the user must respond to the message box before
continuing work in the current application.
vbSystemModal 4096 System modal; all applications are suspended until the user responds to the
message box.
VbMsgBoxSetForeground 65536 Specifies the message box window as the foreground window
vbMsgBoxRtlReading 1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic
systems
The user can set a default button, which dining the nm time the message box default selects a
particular button. This has three values, which are shown below with their information. The next
group of numbers controls which button is the default button for the box. This is summarized in the
following table.
You can combine these options by adding the constants or values together. We can also use
some picture to be shown on the message box, some like exclamation, question marks etc.,
TEXT BOXES: Text boxes are the primary method for accepting input and displaying output
in VB. In fact, printing too many lines of test to a form will often load to run time error and, in any
case, you can’t scroll back through the form to see that may have slipped off the top.
Properties of Text Box
There are around 50 properties for text boxes. Name property is used only for the code you
write, the user never see it. We can also change height, width, left, top, with the properties. You can
also set both the backcolor and forecolor properties for a text box. This can be set using color palette
from the property window.
The enable property affects whether the text box will respond the events. If a text box is disabled the
user cannot enter text inside it. It also has visible property between True or False, with code, in order
to make a text box appear and disappear.
The text boxes are the primary method for accepting input and displaying output in visual
basic. This is the only tool that you can type in during the run time. Text boxes can display large
amount of text which the user can scroll through.
Whatever is typed on the text boxes will be accepted only as strings. Even if a
number is typed it is treated as strings only. Some functions say Val is need to convert in to number
values.
Text box uses around 50 properties now we will look out some special
properties of text boxes.
TEXT: If we want a text box to be empty when application starts, select the text property and blank
out the original settings.
Alignment : The default value is 0, which is left aligned use 1 and text is right aligned. Use of value
2 is centered.
Multiline: This property determines whether a text box can accept more than one line of
Text when the user runs the application. This allows the use of horizontal and vertical
scroll bar; to move around the area.
Scroll Bars :
This property determines whether a textbox has horizontal or vertical scroll bars.
Without scroll bars it becomes much harder for the user to move through the data contained in
the text box.
0 - default value
1— horizontal scroll bar
2 — vertical scroll bar
3 — both horizontal and vertical scroll bar.
Border Style : This sets the border styles of the text box
0 — border disappears
1 - single-width border.
Max length: This property determines the maximum number of characters the text box will accept. 0
- default of about 32000—characters
Any other setting specifies the number he give.
Password character: This property lets you limit what the text box displays. The convention is to use
asterisk (*) Once we set this, the entire textbox character Will look in asterisk.
Locked: It is used to lock the text box and no action can be performed on it as display or type
anything to it.
LABEL: Use labels to display text information that the user does not need to edit. We can still change
the text displayed in your code, by setting the caption property. Probably the most common use for
labels is to identify a text box or other control by describing its contents another common use is to
display help information. This also displays some results that are produced after run time. So the user
can’t change the values as like text box.
Labels support totally 34 possible properties, some properties are same as that of form, text
box and command button properties. When label control is created it automatically sets its default
caption as label1 and label2 and so on.
Common Properties Are
• Caption - sets the caption that is given by the user to identify other control
• Font - sets the font style of the caption
• Height, width - resize of the labels
• Left & top - creates spaces other controls
• Back color - sets the back color of label as user needs
• Fore color - sets the text color of labels
• Enabled - this case T/F to make user use of labels and disables
• Visible- uses T/ F to make labels visible in form or not.
Specific Properties of Labels
There arc five especially useful properties for labels which are listed below.
ALIGNMENT: The alignment property for the label has three possible settings
— Value 0— means the text in the label for a label is left - justified
— Value I — text inside the label will be right - justified
— Values2 this sets the value in center of labels.
Border Style, Back Style
The border style property has two types of values 0 that is default with no borders and value 1
label resembles with a border. The back style property determines whether the label is transparent or
opaque.
Auto Size : The labels can be made to grow automatically in a horizontal direction to encompass the
text you place in them. The default is False and you need to change it to True to take advantage of
these neat features.
Word Wrap : If we set the property to true, the label Will grow in the vertical direction encompass its
contents, but the horizontal size will stay the same. This helps in not breaking any words, we need to
set this property to 1 for using this option 0, 3 default.
PICTURE BOX Picture box, as its name suggest, is a box which can contain a picture. Less
obviously we can draw on a picture box in our own code. A picture box can also be a container for
other controls. So we can group them together.
There are different properties events and methods used in the picture box some are shown
below.
Working with Picture Boxes:
Picture boxes have over 50 properties and respond to 19 events, and you can use any one of 22
methods for them. Some are listed below
Properties of Picture Boxes:
Insert from
The special property is auto size is true the picture box will automatically resize itself to fit the
image.
Methods of Picture Box:
This uses 22 methods some of the main methods are Cls. This erases whatever image and text
were placed in the picture box. Move method moves the picture box around at run time to make
animated effect.
Some events procedures are
Event Occurs
Click when a user clicks an object
Double click When a user double clicks an object.
Drag drop When a user performs a drag operation from
a different object, and releases (drops) the
mouse over the cunent object.
While a user is perfonning a ding opention
Drag over from a different object and the cursor is over
the current control This event is often used to
display a custom icon indicating whether or
not the current control can accept the “Drop”
action.
Got focus When the current object receives the focus.
This can happen when a user click the object
(also triggering the click event),
When someone uses the tab key to give the
object the focus, or when the focus is set to
the object in visual basic code.
Mouse up