Anda di halaman 1dari 11

VISUAL

BASIC
Lesson 1

Using Forms
Form Properties
Form Events

FORM

OBJECTIVES:
1. Learn and appreciate the importance of Form Properties.
2. Investigate how Form Events affect program development in Visual
Basic.

FORMS
Acts as a container of other objects such as controls. Without forms,
controls cannot be defined and used. Forms are the windows that you see at
runtime.

1|Page

FORMS PROPERTIES
Property

Description

AutoRedraw

Used to make graphics in applications persistent.

BackColor

Manipulate the background color of a form or a control.


Programmer selects a color from the Color Palette or
specifies a color in Hex format.

BorderStyle

Defines how the Form window appears. It also specifies


whether the user can resize the Form and determines what
kind of Form you wish to display (0: None, 1: Fixed Single, 2:
Sizable, 3: Fixed Dialog, 4: Fixed ToolWindow, 5: Sizable
ToolWindow)

Caption

Display text in the forms title bar and identifier if minimized.


Mnemonic Access Character setting does not apply to forms.

ControlBox

Placing a standard Windows control-box menu on the upperleft corner of the form.

DrawWidth

Determines the thickness of drawn line, circles, etc.

Enabled

Freeze controls; indicate which controls are not available.

FillColor

Determine fill colors for circles, rectangles drawn using


Circle and Line methods. FillStyle must be set to solid.

Height

Specifies the height of the Form in twips. A twip is 1,440th of


an inch)

Icon

Specifies the filename of the icon graphic image that appears


in the Forms Title Bar

Left

Position of the form/control in relation to the left edge of


the screen/form respectively.

MaxButton

Boolean. Specifies whether a maximize button appears on the


Form.

MinButton

Boolean. Specifies whether a minimize button appears on the


Form.

Mouselcon

Define custom mouse icons. Mouse Pointer must be set to 13Custom.

MousePointer
Moveable

Determines the image of the mouse cursor when the user


moves the mouse pointer over the Form.
Boolean. Specifies whether the user can move the Form at
runtime.

Name
2|Page

Refers to the name of the control or form. It follows the

rules I naming variables but maximum length is 40 characters.


Picture

Graphics into forms, images, and picture boxes. Can directly


work with *.ICO, *.BMP, *.WMF.

ScaleHeight

Measure the inner (without title bar) height of a form or


control.

ScaleMode

Change the unit of measurement used by Visual Basic. Makes


use of the following settings: 0 Custom Values, 1 Twips
(default) there are 1440 twips per logical inch and 567 twips
per logical centimeter, 2 Point there are 72 points per
logical inch, 3 Pixel smallest unit of monitor or printer, 4
Character (Horizontal = 120 twips per unit; vertical = 240
twips per unit), 5 inch, 6 Millimeter, 7 Centimeter.

ScaleWidth

Measure the inner width of a form or control.

StartUpPosition Determines the state (centered or default) of the Form at


application startup.
Top

Specifies the number of twips from the Labels top edge to


the Form windows top edge.

Visible

Boolean. Determines whether the Form appears (True) or is


hidden from the user (False) at runtime.

Width

Holds the width of the Form in twips.

WindowState

Determines the initial state of the Form (0: Normal, 1:


Minimized, 2: Maximized)

EVENTS
Events - are the primary elements of a user and VB interaction. Your
application opens a dialog box when the user selects the Open menu or outputs
the square of two numbers when the user clicks on a button. Selecting the
menu and clicking the button are examples of events.
Events can be keyboard- or mouse-triggered. With the mouse, you can use
the

MouseDown,

MouseUp,

and

MouseMove

events

to

enable

applications to respond to both the location and the state of the mouse.

3|Page

your

How do we create event-handlers then?


When we double click the CommandButton, a Code Window appears like
the one below.

Visual Basic automatically creates an Event Procedure for you in the format:
Private Sub cmdSum_Click()
End Sub
An Event Procedure is simply a block of statement executed when an
event (in this case, a Click) of a particular control is triggered.
Event

Description

Activate

Triggered when the form becomes the active window.

Click

Triggered when the user presses and then releases a mouse


button.
Index - integer that uniquely identifies a control if its in a
control array.

DblClick

Triggered when the user presses and releases a mouse button for
two consecutive times.

Deactivate

Triggered when the form is no longer the active window.

DragDrop

Triggered when a drag-and-drop operation is completed as a


result of dragging a control over a form or a control and releasing
the mouse button or using the Drag method with its action
argument set or to 2 (DROP).
Source - The control being dragged. You can include properties

4|Page

and methods with this argument, for example, Source.Visible = 0

x, y - A number that specifies the current horizontal (x) and


vertical (y) position of the mouse pointer within the target form
or control.
GetFocus

Triggered when the form or control gets the focus.

KeyDown

Triggerd when a key I pressed. It can capture the KEYCODE of


any key.

Keycode

A key code, such as vbKeyF1 (the F1 key) or vbKeyHome (the


HOME KEY). To specify key codes, use the constants in the
Visual Basic (VB) object library in the Object Browser.
Shift - An integer that corresponds to the state of the SHIFT,
CTRL, and ALT keys at the time of the event.

KeyPress

Triggerd when a key is pressed down. It can detect the ANSI


codes of keys.

Keyascii

An integer that returns a standard numeric ANSI keycode.

Load

Triggered when a form is loaded into the computers memory.

MouseDown

Occurs when the user presses on a mouse button. It can detect


which button was clicked.
Button - Returns an integer that identifies the button that was
pressed (MouseDown) or released (MouseUp) to cause the event.
The button argument is a bit field with bits corresponding to the
left button (bit 0), right button (bit 1), and middle button (bit 2).

MouseMove

Triggered whenever the mouse is moved. It shares the same


arguments with the MouseDown event.

MouseUp

Occurs when the user releases a mouse button. It can detect


which button was clicked. It shares the same argument with the
MouseDown event.

Paint

Triggered when a window is moved or if the forms size is


increased (but not when its size is decreased).

QueryUnload

used to determine the manner by which a form was closed.


Cancel - An integer. Setting this argument to any value other
than 0 stops the QueryUnload event in all loaded forms and stops
the form and application from closing.
Unloadmode - A value or constant indicating the cause of the

5|Page

QueryUnload event, as described in Return Values.


RETURN VALUES:
0 - vbFormControlMenu The user the Close command from the
Control menu on the form.
1 vbFormCode The Unload statement is invoked from code.
2 - vbAppWindows

The current Microsoft Windows operating

environment session is ending.


3 - vbAppTaskManager

The Microsoft Widows Task Manager is

closing the application.


4 - vbFormMDIForm

An MDI child form is closing because the

MDI form is closing.


Resize

Triggered whenever a form is resized (both increase and


decrease). It is also triggered whenever a form is loaded onto the
computers memory.
Height - Number specifying the new height of the control.
Width - Number specifying the new width of the control.

Terminate

Triggered when a program is unloaded from the computers


memory.

Unload

Triggered when a form is unloaded from the computers memory.


Cancel - Integer that determines whether the form is removed
from the screen. If cancel is 0, the form is removed. Setting
cancel to any nonzero value prevents the form from being
removed.

6|Page

EXERCISE 1:
Explore your Form by integrating different pictures and labels.

Private Sub Form_Load()


Form1.Picture = LoadPicture("e:\Clipart\Animal Cartoons\G0100846.wmf")
End sub

7|Page

Lesson 2

Using Labels
Label Properties

OBJECTIVES:
1. Familiarize with the label properties.
2. Create and use label control.
LABELS
hold text that appears on the Form. Labels cannot be edited directly an
explicit code assigning a new caption to the Label should be carried out.
LABEL CONTROL PROPERTIES
Property
Alignment

Description
Determines whether the text appears 0: left-justified, 1: rightjustified, or 2: centered within the Labels boundaries.

AutoSize

Boolean. Enlarges the Labels size properties, when True, if you


assign a caption that is too large to fit in the current Labels
boundaries at runtime. If False, the Label truncates the
caption.

BackStyle

Determines whether the background shows through the label


of if the Label covers up it background text, graphics, and
color.

BorderStyle

0: None, 1: Fixed Single. Determines whether a single-line


border appears around the Label.

Caption

Holds the text that appears on the Label.

Enabled

Boolean. Determines whether the Label is active. A disabled


Label does not trigger an even procedure.

Font

Specifies the font of the text. Clicking this property will invoke
a font dialog box in which you can set the font name, style, and
size.

ForeColor

Specifies the color of the text. Programmer selects a color


from the Color Palette or specifies a color in Hex format.

8|Page

Height

Specifies the height of the Label in twips.

Left

Specifies the number of twips from the Labels left edge to the
Form windows left edge.

MousePointer Determines the image of the mouse cursor when the user
moves the mouse pointer over the Label.
TabIndex

Specifies the order of the Label in the focus order.

TabStop

Boolean. Determines whether the Label can receive the focus.

ToolTipText

Holds the text that appears as a tooltip at runtime. A tooltip is


a pop-up description box that appears when the user rests the
mouse pointer over a control.

Top

Specifies the number of twips from the Labels top edge to the
Form windows top edge.

Visible

Boolean. Determines whether the Label appears (True) or is


hidden from the user (False) at runtime. Invisible Labels are only
invisible at runtime.

Width

Holds the width of the Label in twips.

WordWrap

Determines whether the Label expands to fit its caption.

9|Page

EXERCISE 2:
Discover the value and usefulness of the properties found on label.
1. Design the form by putting the needed controls.
2. Customize the controls by changing the properties

Private Sub CmdClear_Click()


Label1.Caption = " "
End Sub
Private Sub CmdClose_Click()
End
End Sub
Private Sub CmdDisp_Click()
Label1.Caption = "Occidental Mindoro State College"
End Sub
Private Sub Form_Load()
Label1.Caption = " "
Label1.Font = "CASTELLAR"
Label1.FontSize = 20
Label1.ForeColor = QBColor(1)
Label1.Alignment = 2
End Sub
3. Save your project and your form the filename is act2(surname).vpb
4. Run your program by pressing the start button.
10 | P a g e

Lesson 3

Selecting Control
Shape Control
Fill Style
Fill Color

OBJECTIVES:
1. Explore the understanding on shape control.
2. Simulate the importance of shape in program design and development.
SHAPE CONTROL
The Shape control provides you with basic shape objects such as
Rectangles, Squares, Ovals, and Circles. The following Form shows each of
these shapes:

Shape control can be drag to the Form,


a default rectangle shape is displayed.
To change the shape, simply change the

Shape property to: 0: Rectangle,


1: Square, 2: Oval, 3: Circle, 4: Rounded
Rectangle and 5: Rounded Square.

Fill Shapes with a color by setting the


FillStyle property to 0: Solid and setting
a color to the FillColor property. You may
also fill the Shapes with one of the
pre-defined patterns: 2: Horizontal,
3: Vertical Line, 4: Upward Diagonal,
5: Downward Diagonal, 6: Cross, and
7: Diagonal Cross.

11 | P a g e