Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.

Similar presentations


Presentation on theme: "Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting."— Presentation transcript:

1 Basic Controls & Properties Chapter 2

2 Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting Properties with Code

3 The Visual Basic IDE

4 The Workspace & Toolbox

5 Selecting Tools u 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

6 The Project Window u This window allows you to select and open one or more forms that are used in a given project.

7 u You may use this window to adjust the position of the form on the CRT screen. u Clicking on the “X” will close this window and leave room for other things. The Form Layout Window

8 u 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

9 The Command Control u The command control is one of the most important tools in the toolbox u Double clicking on the command button icon will install a command button on the working form Command Button

10 Adding a Command Button u The command buttons are named, by default Command1, Command2, etc. u They may be moved or changed in size using the mouse

11 Properties of Command Buttons u Each command button has several properties. govern the button’s appearance and behavior u 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

12 Highlighting a Property u When you highlight a property, its definition appears below the properties window

13 Names and Captions  Clicking on the (name) property lets us name it “ cmdstop ”, (note the name starts with “cmd”) u Changing the caption to “Stop” gives the user an idea as to the button’s function

14 Naming Convention u 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 u Captions are used to convey information to the user  They can change as the program runs  They may contain any letters, numbers, spaces, etc.

15 Command Buttons & The Program Editor u Visual Basic (VB) supports a text editor (not a word processor) that permits the writing and modification of program code u The program editor is one of two sub-windows that appears in the Workspace  The other is the Forms window u Many of the commands used in the program editor are like those used in word processors, but there are differences

16 Entering the Editor u The editor is normally entered by “double clicking” on an “Event Producing Object” in the workspace. u The result is a code window which opens with the “subroutine” describing that event as the focus.

17 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

18 The Label Control u The label control is an object with 37 named Properties u You can adjust its size and position with the mouse u You can change its (name) its caption and visibility using the Properties window

19 Label Control Properties

20 Using Labels u The label control is usable only for output  It cannot accept input from the user u 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 u Labels can be sized and moved using the mouse.

21 A Program Using a Label

22 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

23 Naming Convention  Labels should be given a (name) that begins with “ lbl ”. u 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 u The Visible property may be either True or False  If false, the label is not displayed

24 3. The Text Box Control u Labels are designed to be used for output u Command buttons can accept input from the user, but only of a limited nature u The text box control allows the user input data

25 Text Box Properties u The text property contains the string of text displayed by the text box u Unlike labels, by default this text can be edited by the user at runtime u The proper prefix for text box names is txt u Text boxes do not have Caption property!

26 4. The Picture Box u The Picture box control can be used to display a picture on the form u The proper prefix for picture box names is pct u 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


Download ppt "Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting."

Similar presentations


Ads by Google