Basic Controls - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Basic Controls

Description:

Using the toolbox and the Workspace Window you can build a form that has nearly ... A command button with an ellipsis (...) will be displayed ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 27
Provided by: jayso
Category:

less

Transcript and Presenter's Notes

Title: Basic Controls


1
Basic Controls Properties
Chapter 2
2
Overview
  • VB-IDE
  • Basic Controls
  • Command Button
  • Label
  • Text Box
  • Picture Box
  • Program Editor
  • Setting Properties with Code

3
The Visual Basic IDE
4
The Workspace Toolbox
5
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

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

7
The Form Layout Window
  • 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.


8
The Properties 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


9
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
10
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

11
Properties of Command Buttons
  • Each command button has several properties.
    govern the buttons 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

12
Highlighting a Property
  • 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)
  • Changing the caption to Stop gives the user an
    idea as to the buttons function

14
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 programs
    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.

15
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

16
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.

17
Entering Event Code
  • Double clicking on the cmdStop button itself,
    causes the Code window to open
  • The VB commands that define the buttons function
    go here
  • The End command terminates the VB program

18
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

19
Label Control Properties
20
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.

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.
  • 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

24
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

25
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!

26
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
Write a Comment
User Comments (0)
About PowerShow.com