Download - Basic Controls & Properties
![Page 1: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/1.jpg)
Basic Controls & Properties
Chapter 2
![Page 2: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/2.jpg)
Overview
VB-IDE Basic Controls
Command Button Label Text Box Picture Box
Program Editor Setting Properties with Code
![Page 3: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/3.jpg)
The Visual Basic IDE
![Page 4: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/4.jpg)
The Workspace & Toolbox
![Page 5: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/5.jpg)
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
![Page 6: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/6.jpg)
The Project Window
This window allows you to select and open one or more forms that are used in a given project.
![Page 7: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/7.jpg)
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
![Page 8: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/8.jpg)
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
![Page 9: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/9.jpg)
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
![Page 10: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/10.jpg)
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
![Page 11: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/11.jpg)
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
![Page 12: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/12.jpg)
Highlighting a Property
When you highlight a property, its definition appears below the properties window
![Page 13: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/13.jpg)
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
![Page 14: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/14.jpg)
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.
![Page 15: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/15.jpg)
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
![Page 16: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/16.jpg)
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.
![Page 17: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/17.jpg)
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
![Page 18: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/18.jpg)
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
![Page 19: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/19.jpg)
Label Control Properties
![Page 20: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/20.jpg)
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.
![Page 21: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/21.jpg)
A Program Using a Label
![Page 22: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/22.jpg)
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
![Page 23: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/23.jpg)
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
![Page 24: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/24.jpg)
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
![Page 25: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/25.jpg)
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!
![Page 26: Basic Controls & Properties](https://reader036.vdocuments.mx/reader036/viewer/2022062301/56815a87550346895dc7f857/html5/thumbnails/26.jpg)
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