Top Banner
Chapter 4 Enhancing the Graphical User Interface Multiple Forms, Controls, and Menus 4 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, By Carlotta Eaton
36
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: VB6-Ch4

Chapter 4Enhancing the Graphical User

Interface

Multiple Forms, Controls, and

Menus

4

Exploring Microsoft Visual Basic 6.0Copyright © 1999 Prentice-Hall, Inc.

By Carlotta Eaton

Page 2: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 2

Objectives

1. How to design a good user interface2. Use Toolbox tools to create and modify

forms and controls3. Multiple Document Interface (MDI) vs.

Single Document Interface (SDI) vs. Explorer-style interface

4. Create input features such as text boxes, labels and command buttons

Page 3: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 3

Objectives

5. Include graphics using picture box or image controls

6. Create a Graphical User Interface with menus

7. Include file management features using drive list boxes, directory list boxes and file list boxes

8. Include frames, check boxes, option buttons, combo boxes, and list boxes

Page 4: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 4

Designing the GUI

Interface StylesMultiple Document Interface (MDI)Single Document Interface (SDI)Explorer-style interface

Page 5: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 5

Multiple Document Interface

Parent Form

Child Form

Child Form

Page 6: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 6

Single Document Interface

Independent Form

Independent Form

Page 7: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 7

Explorer-style interface

Left pane browsing controls

Right pane detailed view

Page 8: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 8

Five Principles of GUI Design

Principle 1: Know Your End UserPrinciple 2: Be ConsistentPrinciple 3: Show and Use Informative

Graphics and MessagesPrinciple 4: Keep It SimplePrinciple 5: Let the User Control the

Application

Page 9: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 9

Principle 1: Know Your End User

Who is my audience?Will be used by children, adults or

both?What is reading level of users?If retired adults, use large font.Write down as much as you know

about your end user before beginning design.

Page 10: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 10

Principle 2: Be Consistent

Use Windows Guidelines - Close button Windows standard fonts - Arial, Times

New Roman, and MS Sans Serif Establish font color and size, background

color, and foreground color Use menus and standard menu positions See Appendix D - Standard Menus for

Windows Applications

Page 11: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 11

Principle 3: Show and Use Informative Graphics and

Messages

Show user, instead of tellingUse informative graphics, instead

of merely creative graphicsGraphics especially useful for

international applicationsGUI analogy - dashboard of carUse symbols, not words

Page 12: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 12

Principle 4: Keep It Simple

KISS “Keep it simple sweetie”If interface looks difficult, it will be

hard to useUse several forms instead of a

single cluttered formGroup items, use tabbed formatSet default options for user

Page 13: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 13

Principle 5: Let the User Control the Application

Conversation between computer and end user

Let end user decide tasks and orderProgrammer controls computer’s

responses to end user Visual Basic is event-driven so this

is relatively easy to achieve

Page 14: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 14

Form Designer Grid

Twips - screen-independent unit

Pixels - picture elements, screen-dependent unit

See Appendix C - The Toolbox, Toolbars, and Controls

Page 15: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 15

The Learning Arithmetic Project

Game to practice addition, subtraction, multiplication and division skills

Numbers from 0 to 9 Child in grade 3, 4 or 5 Give feedback to child Use Window

Calculator accessory as model

Page 16: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 16

GUI Enhancement with the Learning Arithmetic Project

Hands-On Exercise 1 Use the Application Wizard Save your forms and project files Modify the Splash form Add the Calculator form Add the Bears form Write the Module code Run and test the project Debug your project Print your project and exit

Page 17: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 17

The Toolbox

Intrinsic Controls - always included in the Toolbox

ActiveX Controls - separate files with ocx file extension

Insertable Objects - objects from another application such as a spreadsheet, or document

Page 18: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 18

Intrinsic Controls

Text box

Picture box

Command button

Vertical scroll bar

Drive list

File list box

Line

Data

Option button

Pointer tool

List box

Label

Frame

Check box

Combo box

Horizontal scroll bar Timer

Directory list box

Shape

Image

OLE container

Page 19: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 19

Get Input

Text box - text inputHorizontal Scroll bars - navigate choicesVertical Scroll bars - navigate choicesCheck box - more than one choiceOption buttons - mutually exclusive

choices

List box - 1 choice from list

Combo box - choose or type a choice

Page 20: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 20

Get Input

Tabbed dialog - present many optionsMsgBox function - prompt user or display

messageInputBox function - present predefined

dialog boxesCommon dialog - display standard dialog

boxes such as Open, Save and PrintCustomized dialog box - create your own

Page 21: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 21

Display Graphics

Image - use to create an icon command button, decorative images

Picture box - use to create a toolbarLine - draw a straight line segmentShape - draw a rectangle, square, ellipse,

or circleBackground Property - background

imageLoadPicture function - use at runtime

Page 22: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 22

File System Controls

Drive list box - display list of disk drives

Directory list box - display list of folders (directories) and paths

File list box - display list of files

Page 23: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 23

Miscellaneous Controls

Frame - use to group controls together

Timer - use to trigger simple animations or like a stopwatch

OLE container - use to link or embed objects from other applications

Page 24: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 24

Data Access Controls

Data Control display, edit and update data from

existing databases uses same database engine that

powers Microsoft Access

Page 25: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 25

Set Properties with Code

name.property = settingWhere

name is the name of the control or form

. (period) is required

property is the property to set or modify

= is required

setting is the setting of the property

Examples:imgWorld.Visible = True

txtName.Text = “Sarah”

Page 26: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 26

Create the Icon Explorer Project using File System

ControlsHands-On Exercise 2

Create a new project Add the existing starter form Add a Splash form Add the Main module Modify the Main form Code the Main form Run and debug the project Add code to display icons Run and debug the new code Print your project and exit

Page 27: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 27

Elements of a Menu

Menu bar

Menu title

Separator bar

Menu items

Page 28: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 28

The Menu Editor

Menu title

Menu items

Separator bar

Menu control properties

Menu control list box

Page 29: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 29

Setting Properties for Menu Commands

Name property - assigns the name used to refer to the menu control in your code

Enabled property - menu control appears dimmed (grayed out) when not enabled

Caption property - assigns the command to display on the menu bar or submenus

Page 30: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 30

Menus and the Menu Editor

Access key - underlined keyboard alternative to a menu command - Press Alt + key

Shortcut key - assigned to most frequently used menu items - Press Ctrl + key

Separator Bar - divides menu items into logical groupings

Page 31: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 31

Menu Design

Use short menu names, single wordUse unique menu items for each

menuGroup menus logicallyChoose a logical access key for

menu itemsChoose logical keyboard shortcuts

for most commonly used commands

Page 32: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 32

Add Menus to the Learning Arithmetic

ProjectHands-On Exercise 3

Open the Learning Arithmetic project Save project files with a new name Add menu titles Add menu items Modify the About form Add the HowTo form and controls Add code to activate the menus Test the menus and forms

Page 33: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 33

Summary ...

Design GUIs using 5 basic design principles1. Know your end user

2. Be consistent3. Use informative graphics and messages4. Keep it simple5. Let the user control the application

Design GUI on paper first

Page 34: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 34

Summary

Add controls to forms using tools from the toolbox

Intrinsic controls are always in the toolbox

ActiveX controls and Insertable Objects can be added to the toolbox

Use the Menu Editor to add menusAdd code to activate the menus

Page 35: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 35

Practice with Visual Basic

1. Controls Demonstration Sample2. MDI vs. SDI Interface Style3. A Successful Windows Application4. Graphic Explorer Project5. My Calendar

Page 36: VB6-Ch4

Exploring MS Visual Basic 6

Copyright 1999 Prentice-Hall, Inc. 36

Case Studies

Create a PrototypeInsertable ObjectsActiveX ControlsControls from the Web