Lesson I

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

Lesson I.

Forms, Labels, and Shapes

Objectives
  To be able to create, execute, and save a VB project
  To interactively design a simple interface by selecting, placing and sizing screen objects from the
toolbox
  To be able to use the Pointer to select controls
  To be able to customize the Form using properties
  To use and be familiar with the Label control and its properties
  To use and be familiar with Shapes and their common properties
  To be familiar with VB events

Notes
IN FOCUS: FORMS
Forms are the windows that you see at runtime. They serve as containers of controls such as Labels and
CommandButtons. The following table lists the Form’s properties.

Property Description
BackColor Specifies the Form’s background color. Programmer selects a color
from the Color Palette or specifies a color in Hex format.
BorderStyle Determines 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 Specifies the text on the Form’s Title Bar at runtime.
Enabled Boolean. Determines whether the Form is active. A disabled Form
does not trigger an event. All controls on the Form are also
disabled.
Height Specifies the height of the Form in twips. A twip is 1,440 th of an
inch)
Icon Specifies the filename of the icon graphic image that appears in the
Form’s Title Bar
Left Specifies the number of twips from the Label’s left edge to the
Form window’s left edge.
MaxButton Boolean. Specifies whether a maximize button appears on the
Form.
MinButton Boolean. Specifies whether a minimize button appears on the Form.
MousePointer Determines the image of the mouse cursor when the user moves
the mouse pointer over the Form.
Moveable Boolean. Specifies whether the user can move the Form at runtime.
Picture Determines the graphic image that appears on the Form’s
background.
StartUpPosition Determines the state (centered or default) of the Form at
application startup.
Top Specifies the number of twips from the Label’s top edge to the
Form window’s 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)
Form’s Events
Form events are events that the Form can accept. The following are common ones:

7
Event Description
Load Occurs when a Form is loaded.
Unload Occurs when a Form is about to be removed from the screen.
Resize Occurs whenever a Form is resized, either by user interaction or
through code.
Activate Occurs when an object becomes the active Form. An active Form
appears in the foreground with a highlighted Title Bar.
Deactivate Occurs when a Form is no longer active.
More events are discussed in Lesson II.

IN FOCUS: LABELS
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. You use a Label, as its name obviously implies, to label a
control, to provide instructions, etc. The following table lists most common Label control properties.

Property Description
Alignment Determines whether the text appears 0: left-justified, 1: right-
justified, or 2: centered within the Label’s boundaries.
AutoSize Boolean. Enlarges the Label’s size properties, when True, if you
assign a caption that is too large to fit in the current Label’s
boundaries at runtime. If False, the Label truncates the caption.
BackColor Specifies the Label’s background color. Programmer selects a color
from the Color Palette or specifies a color in Hex format.
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.
Height Specifies the height of the Label in twips.
Left Specifies the number of twips from the Label’s left edge to the Form
window’s 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 Label’s top edge to the Form
window’s 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.

8
IN FOCUS: RUNNING, PAUSING, & STOPING A VB PROGRAM
You can run, pause, and stop VB applications by pressing the control buttons on the Tool Bar or by clicking
the Run menu and selecting the appropriate menu item.

Click this to run the application.


Click this to pause the application.
Click this to terminate the application. You can also click the Close button
on the Title Bar of the application.

IN FOCUS: SELECTING CONTROLS


The Pointer is one indispensable tool. When we move and resize control or when we modify the properties
of a control, we use the Pointer tool. How do we use the Pointer in selecting controls?

  If you want to select a control, simply click the Pointer on the Toolbox and click the control you
would like to select.
  If you want to select multiple controls, hold down the Ctrl key and click each control. You may
also just lasso multiple controls by dragging a square around the controls using the mouse.

IN FOCUS: 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:

When you drag a Shape control to the Form, a rectangle is displayed. To change the shape, simply change
the Shape property to:

0: Rectangle
1: Square
2: Oval
3: Circle
4: Rounded Rectangle
5: Rounded Square

By default, Shapes are transparent – all you see is the outline of a white shape. If you want the color of the
Form to appear through the Shape, (the Shape shows whatever it covers), set the BackStyle to 0:
Transparent.

9
You can 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.

You can also modify the border (or outline) of the Shapes. The BorderStyle property determines how the
Shape’s borders would look like. When set to 0: Transparent, you do not see any border. The border can
also be 1: Solid Line (the default), 2: Dashes, 3: Dots, 4: Dash Dots, 5: Dash Dot Dots, 6: Inside Solid . The
BorderWidth determines the width of the Shape’s border. Default value is 1. The bigger this value, the
thicker the border. The Visible property determines whether the Shape should be displayed ( True) or not
(False) at runtime.

10
Lesson in Action

1. Create a new project. When you fire up VB, a New Project dialog box appears. Select Standard
Exe, and click the Open button. If you want another project, just click the File menu, then New
Project.
2. Customize the Form.
 Name frmMain
 Caption My First Visual Basic Application
 MinButton False
 MaxButton False
 StartUpPosition Center Screen
 Height 3135
 Width 4620
 BackColor White
3. Place a Label control on the form.
4. Customize the Label.
 Name lblBanner
 Caption Welcome to Visual Basic
 Font Arial, Regular
 Size 24
 BackColor Yellow
 ForeColor Blue
 Width 3735
 Height 1215
 Top 720
 Left 360
5. Run your application by clicking the 4 button.
6. Save your work as Lesson1.vbp. Do this by clicking the File menu, then Save Project.
7. If you want to load your project again, simply click the File menu, then Open Project. A dialog box
appears. Just select the Drive and Directory where your project is saved.

On your Own

1. Create an Application displaying your name. Consider the following specifications:


  Display the Maximize and Minimize buttons.
  Your name should be displayed in Arial font, Size 18, Bold, color Blue.
  Display a rectangle Shape control (BorderWidth=3, BorderStyle=Dots) around the Label.
  Label should be transparent.
  Form should have a white Background color.
  Display an icon on the Title Bar (icon file will be provided by the instructor).

11
12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy