Upload
antony-campbell
View
217
Download
0
Tags:
Embed Size (px)
Citation preview
Basic Controls & Properties
Chapter 2
Overview
VB-IDE Basic Controls
Command Button Label Text Box Picture Box
Program Editor Setting Properties with Code
The Visual Basic IDE
The Workspace & Toolbox
Selecting Tools
Using the toolbox and the Workspace Window you can build a form that has nearly any desired appearance Double click on an icon in the toolbox to create a new
instance of that type of object in your workspace These objects are called controls
Using the mouse, a control can be resized or moved
The Project Window
This window allows you to select and open one or more forms that are used in a given project.
You may use this window to adjust the position of the form on the CRT screen.
Clicking on the “X” will close this window and leave room for other things.
The Form Layout Window
This window allows you to examine and modify the various properties of control objects in a program Properties govern the
appearance and behavior of a control object
They may be modified using the properties window, or by VB code
The Properties Window
The Command Control The command control
is one of the most important tools in the toolbox
Double clicking on the command button icon will install a command button on the working form
Command Button
Adding a Command Button
The command buttons are named, by default Command1, Command2, etc.
They may be moved or changed in size using the mouse
Properties of Command Buttons
Each command button has several properties. govern the button’s appearance and behavior
The most important are the (name) and the caption (name) is how a programmer can
refer to the button in VB code caption is the text a user will see
displayed inside the button
Highlighting a Property
When you highlight a property, its definition appears below the properties window
Names and Captions
Clicking on the (name) property lets us name it “cmdstop”, (note the name starts with “cmd”)
Changing the caption to “Stop” gives the user an idea as to the button’s function
Naming Convention
Good practice in Visual Basic suggests that we should name all objects in a program with names that indicate their function These names are invariant during a program’s execution and are
seen only by programmers Command buttons names should begin with the prefix “cmd” Names should begin with the prefix for the given object type, and
should contain only letters and numbers
Captions are used to convey information to the user They can change as the program runs They may contain any letters, numbers, spaces, etc.
Command Buttons & The Program Editor
Visual Basic (VB) supports a text editor (not a word processor) that permits the writing and modification of program code
The program editor is one of two sub-windows that appears in the Workspace The other is the Forms window
Many of the commands used in the program editor are like those used in word processors, but there are differences
Entering the Editor
The editor is normally entered by “double clicking” on an “Event Producing Object” in the workspace.
The result is a code window which opens with the “subroutine” describing that event as the focus.
Entering Event Code
Double clicking on the “cmdStop” button itself, causes the Code window to open The VB commands that
define the button’s function go here
The “End” command terminates the VB program
The Label Control The label control is an
object with 37 named Properties
You can adjust its size and position with the mouse
You can change its (name) its caption and visibility using the Properties window
Label Control Properties
Using Labels
The label control is usable only for output It cannot accept input from the user
Its size, shape, color, visibility and the form of the information presented can be controlled By editing its properties By writing VB code to change its properties
Labels can be sized and moved using the mouse.
A Program Using a Label
Using a Label
When program execution begins, the system starts as in “A”, when the cmdby button is pressed the system goes to “B”
Repeated pressing of the cmdby button bounces the system between the two states
Naming Convention
Labels should be given a (name) that begins with “lbl”.
The Caption property of a label may be anything that makes sense; one or more words or symbols. Caption is displayed for the user (name) is only accessible to the programmer
The Visible property may be either True or False If false, the label is not displayed
3. The Text Box Control
Labels are designed to be used for output Command buttons can accept input from
the user, but only of a limited nature The text box control allows the user
input data
Text Box Properties
The text property contains the string of text displayed by the text box
Unlike labels, by default this text can be edited by the user at runtime
The proper prefix for text box names is txt
Text boxes do not have Caption property!
4. The Picture Box The Picture box control can be
used to display a picture on the form
The proper prefix for picture box names is pct
Click on its Picture property A command button with an ellipsis
(…) will be displayed By clicking on the button, a dialog
box will appear to select the graphic file to display within the picture box control