Chapter 2. Creating Applications with Visual Basic Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of

Similar documents
Dive Into Visual C# 2008 Express

Dive Into Visual C# 2010 Express

Introductionto the Visual Basic Express 2008 IDE

Programming in C# Project 1:

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.

Full file at

Tutorial 3 - Welcome Application

Chapter 2. Ans. C (p. 55) 2. Which is not a control you can find in the Toolbox? A. Label B. PictureBox C. Properties Window D.

Full file at Programming in Visual Basic 2010

Program and Graphical User Interface Design

LESSON B. The Toolbox Window

Visual Basic Program Coding STEP 2

CIS 3260 Intro. to Programming with C#

Introduction to the Visual Studio.NET Integrated Development Environment IDE. CSC 211 Intermediate Programming

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

INFORMATICS LABORATORY WORK #4

3. The first step in the planning phase of a programming solution is to sketch the user interface.

Visual C# Program: Temperature Conversion Program

PowerPoint 2016 Building a Presentation

2 The Stata user interface

Tutorials. Lesson 3 Work with Text

Introduction to the Visual Basic Express 2005IDE

Visual C# Program: Resistor Sizing Calculator

Interface Design in C#

Using Visual Basic Studio 2008

2 USING VB.NET TO CREATE A FIRST SOLUTION

CST242 Windows Forms with C# Page 1

Corel Ventura 8 Introduction

LESSON A. The Splash Screen Application

Microsoft Excel 2010 Tutorial

This is a demonstration of how you can create a Microsoft Power Point presentation:

Excel Select a template category in the Office.com Templates section. 5. Click the Download button.

Microsoft. An Introduction

Lesson 1 Introduction to LabVIEW. TOPICS LabVIEW Environment Front Panel Block Diagram Dataflow Programming LabVIEW Help and Manuals Debugging a VI

IBM Rational Rhapsody Gateway Add On. User Guide

NiceForm User Guide. English Edition. Rev Euro Plus d.o.o. & Niceware International LLC All rights reserved.

How do I make a basic composite or contact sheet?

Chapter 13 Working with Styles

Center for Faculty Development and Support Making Documents Accessible

MICROSOFT WORD 2010 BASICS

Correcting Grammar as You Type

Introduction to Microsoft Publisher

Welcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline

Controls. By the end of this chapter, student will be able to:

Table of Contents. iii

2. In the Start and End Dates section, use the Calendar icon to change the Displayed Start Date to 1/1/2015 and the Displayed End Date to 5/31/2015.

Movie Maker Tutorial created by Cheryl McKnight

STAR OFFICE WRITER. Lesson 2

Microsoft PowerPoint 2013 Beginning

Correcting Grammar as You Type. 1. Right-click the text marked with the blue, wavy underline. 2. Click the desired option on the shortcut menu.

DEVELOPING DATABASE APPLICATIONS (INTERMEDIATE MICROSOFT ACCESS, X405.5)

Microsoft Excel Level 2

OPTOTERMINAL QLARITY FOUNDRY USER'S MANUAL REVISION 2.5

Microsoft Visual Basic 2005 CHAPTER 5. Mobile Applications Using Decision Structures

Visual BASIC Creating an Application. Choose File New Project from the menu

Microsoft Excel 2010

How to lay out a web page with CSS

Microsoft PowerPoint 2010 Beginning

Full file at Chapter 2: Creating a User Interface

The Mathcad Workspace 7

Departme and. Computer. CS Intro to. Science with. Objectives: The main. for a problem. of Programming. Syntax Set of rules Similar to.

Chapter 5. Inserting Objects. Highlights

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations

Microsoft PowerPoint Tutorial

Word Select New in the left pane. 3. Select Blank document in the Available Templates pane. 4. Click the Create button.

Rock-Paper-Scissors Multiple versions Nested If / Else If / Else Random Numbers

Chapter 7 Inserting Spreadsheets, Charts, and Other Objects

Stat-VU Version 3.2 User s Guide

for G.C.E. Ordinary Level Examination

Table of Contents Lesson 1: Introduction to the New Interface... 2 Lesson 2: Prepare to Work with Office

The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear.

Microsoft Visio 2010

TABLE OF CONTENTS TABLE OF CONTENTS... 1 INTRODUCTION... 2 USING WORD S MENUS... 3 USING WORD S TOOLBARS... 5 TASK PANE... 9

Using SymPrint to Make Overlays, Templates & More...

Basic Concepts. Launching MultiAd Creator. To Create an Alias. file://c:\documents and Settings\Gary Horrie\Local Settings\Temp\~hh81F9.

First Visual Basic Lab Paycheck-V1.0

W-E

Display Systems International Software Demo Instructions

ABOUT THIS COURSE... 3 ABOUT THIS MANUAL... 4 LESSON 1: MANAGING LISTS... 5

Recommended GUI Design Standards

Introducing Gupta Report Builder

CHAPTER 1 COPYRIGHTED MATERIAL. Finding Your Way in the Inventor Interface

How to Spice Up Your Forms Using Crystal

Chapter 2 Visual Basic, Controls, and Events. 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual Basic Events

Academic Word Processing with Word 2003

Chapter 2 Visual Basic Interface

How to Construct. Accessible Talking Books MAC

Dataflow Editor User Guide

Stamina Software Pty Ltd. TRAINING MANUAL Viságe Reporter

Microsoft Word Training

November Copyright 2016 Open Systems Holdings Corp. All rights reserved.

Create and edit text. Create the title text First you ll create the title text for the car rental ad.

WEEK NO. 12 MICROSOFT EXCEL 2007

Getting Started Guide

Creating Forms. Starting the Page. another way of applying a template to a page.

Graphical User Interface Canvas Frame Event structure Platform-free GUI operations Operator << Operator >> Operator = Operator ~ Operator + Operator

Microsoft PowerPoint 2007 Beginning

Getting Started The Outlook Web Access Window

JUN / 04 VERSION 7.1 FOUNDATION

Computer Nashua Public Library Introduction to Microsoft Word 2010

Transcription:

Chapter 2 Creating Applications with Visual Basic Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Section 2.1 FOCUS ON PROBLEM SOLVING: BUILDING THE DIRECTIONS APPLICATION In this section you create your first Visual Basic application: a window that displays a map and road directions to a hotel. In the process you learn how to place controls on a form and manipulate various properties. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Define What the Application is To Do Purpose: Display a map to the Highlander Hotel Input: None Process: Display a form Output: Display on the form a graphic image showing a map Chapter 2 - Slide 4

Visualize the Application and Design Its User Interface Below is a sketch of the application s form Chapter 2 - Slide 5

Determine the Controls Needed Control Type Control Name Description Form Form1 A small form that will serve as (Default Name) the window onto which the other controls will be placed Label Label1 Displays the message (Default Name) "Directions to the Highlander Hotel" PictureBox PictureBox1 Displays the graphic image (Default Name) showing the map to the hotel Chapter 2 - Slide 6

Define Relevant Property Values for Each Control Form Name: Form1 Text: "Directions" Label Name: Label1 Text: "Directions to the Highlander Hotel" TextAlign: MiddleCenter Font: Microsoft sans serif, bold, 18 point PictureBox Name: PictureBox1 Picture: HotelMap.jpg SizeMode: StretchImage Chapter 2 - Slide 7

Create the Forms and Other Controls Using Visual Basic Establish the Form and set its Text property Add a Label control Position and resize it on the form Set Text, TextAlign, and Font properties Add a PictureBox control Position and resize it on the form Set Image property to display HotelMap.jpg Run the application Close and save the application Chapter 2 - Slide 8

Design Mode, Run Mode, and Break Mode Visual Basic has three modes in which it operates: Design Mode the mode in which you create the application also known as design time Run Mode executes the application in the Visual Studio environment also known as run time Break Mode momentarily suspends execution of a running application for testing and debugging purposes Chapter 2 - Slide 9

Project Organization On Disk User creates a new project in Visual Studio A solution and a folder are created at the same time with the same name as the project The project belongs to the solution Multiple projects can be included in a solution The folder stores files related to the project including: A solution file (.sln) A project file (.vbproj) Chapter 2 - Slide 10

Opening an Existing Project Use Recent Projects list on Start Page Provided it hasn t been moved or deleted Use Open Project button on Start Page Then browse using Open Project dialog box Use Open Project option on File menu Then browse using Open Project dialog box Chapter 2 - Slide 11

Properties Window Used to view and modify the property values of a given object Two views of the properties are available: Alphabetic (across all properties) Categorized (groups properties by logical use) Chapter 2 - Slide 12

Section 2.2 FOCUS ON PROBLEM SOLVING: RESPONDING TO EVENTS An application responds to events, such as mouse clicks and keyboard input, by executing code known as event handlers. In this section, you write event handlers for the Directions application. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Modify the Directions Application The Highlander Hotel manager would like you to add the following items to the application: A Label containing the written directions A Button to display the directions A Button to exit the application Chapter 2 - Slide 14

Controls to be Added Control Type Control Name Description Label lbldirections Displays written directions to the hotel Button btndisplaydirections When clicked, causes lbldisplaydirections text to appear on the form Button btnexit Stops the application when clicked Chapter 2 - Slide 15

Control Properties Label Name: lbldirections Text: Traveling on I-89, etc Visible: False Button Name: btndisplaydirections Text: Display Directions Button Name: btnexit Text: Exit Chapter 2 - Slide 16

The Code Window Double-clicking a control in design mode: opens the code window creates a code template for the control s event handler where you fill in the code for the event Chapter 2 - Slide 17

The Click Event Handler for btndisplaydirections Chapter 2 - Slide 18

Changing a Control s Visible Property in Code Specify the control name (lbldirections) Then a dot Then the PropertyName (Visible) For example: lbldirections.visible refers to the Visible property of the lbldirections control The visible property values may only be true or false Chapter 2 - Slide 19

The Assignment Statement Specify the item to receive the value Then the equal symbol Then the value to be assigned For example: lbldirections.visible = True Assigns the value True to the Visible property of the lbldirections control Causes the text of the lbldirections control to become visible to the user Chapter 2 - Slide 20

Switching Between the Code Window and the Designer Window Window Tabs Solution Explorer Icons Menu Bar Keyboard Shortcuts F7 opens the Code Window Shift + F7 opens the Designer Window Chapter 2 - Slide 21

The Click Event Handler for btnexit Chapter 2 - Slide 22

Use Visual Basic to Update the Application Place the label and the buttons on the form Enter the code for the two procedures Test the application Chapter 2 - Slide 23

Changing Text Colors Color properties for a control: BackColor: Sets the background (fill) color ForeColor: Sets the foreground (text) color In the properties window: click on the down arrow select a color from the list Chapter 2 - Slide 24

Setting the FormBorderStyle Property Border style properties for a form: Sizable: (Default) Has min, max, and close buttons; can be resized by dragging edges Fixed3D: Has a 3D look; min, max, and close buttons; cannot be resized FixedSingle: Has single line border; min, max, and close buttons; cannot be resized Chapter 2 - Slide 25

Locking the Controls Locking controls prevents them from being moved around during design time To Lock Controls: right-click an empty space on the form select Lock Controls from the menu To Unlock Controls: right-click an empty space on the form select Lock Controls from the menu Control Locking has a Toggle Effect: Follow the same steps to lock/unlock controls Chapter 2 - Slide 26

Printing Your Code To print a project s code: open the Code window click File on the menu bar click on the Print command Using the keyboard shortcut: open the Code Window Ctrl + P to print Chapter 2 - Slide 27

Using IntelliSense IntelliSense is a feature that provides automatic code completion as you type programming statements Press the Tab key to use IntelliSense For Example: Chapter 2 - Slide 28

Section 2.3 MODIFYING A CONTROL S TEXT PROPERTY WITH CODE Quite often, you will need to change a control s Text property with code. This is done with an assignment statement. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Modifying the Text Property in Code Suppose a form is established with a label lblmessage whose Text property is: 1 Kilometer =? And on a btnfeet button click, we want to change the value of the text property to: 1 Kilometer = 3,281 feet Chapter 2 - Slide 30

Modifying the Text Property in Code Private Sub btnfeet_click( ) Handles btnfeet.click ' Display the conversion to feet. lblmessage.text = "1 Kilometer = 3,281 feet" End Sub Assigns the string to the right of the equal sign to the text property of lblmessage This replaces the previous text property of lblmessage with the new value shown Chapter 2 - Slide 31

Section 2.4 THE AUTOSIZE, BORDERSTYLE, AND TEXTALIGN PROPERTIES The Label control s AutoSize property determines whether a label will change size automatically to accommodate the amount of text in its Text property, or remain a fixed size. The BorderStyle property allows you to set a border around a Label control. The TextAlign property determines how the text is aligned within the label. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

The AutoSize Property AutoSize is a Boolean (either True or False) Property of labels False (the default) means the box size will not change, regardless of the amount of text assigned to it True means the box will automatically resize itself to fit the amount of text assigned to it Chapter 2 - Slide 33

The BorderStyle Property BorderStyle determines the look of the box None (the default) means no border FixedSingle results in a border one pixel wide Fixed3D gives the border a recessed 3- dimensional look Chapter 2 - Slide 34

The TextAlign Property The value of TextAlign establishes the alignment (or justification) of the text: Chapter 2 - Slide 35

The TextAlign Property You can change a label s TextAlign property with code at runtime For example: Assume an application uses a Label control named lblreporttitle The following statement aligns the control s text with the middle and center of the control s bounding box lblreporttitle.textalign = ContentAlignment.MiddleCenter Chapter 2 - Slide 36

Section 2.5 DISPLAYING MESSAGE BOXES You can use the MessageBox.Show method to display a message box, which is a dialog box that pops up, showing a message to the user. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

The Message Box A message box is a small window sometimes referred to as a dialog box a convenient way to display output to the user displayed until the OK button is clicked For example: MessageBox.Show("Hello World!") MessageBox dot Show string Message enclosed in parentheses Chapter 2 - Slide 38

Section 2.6 CLICKABLE IMAGES Controls other than buttons can have Click event handlers. In this section, you learn to create PictureBox controls that respond to mouse clicks. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

PictureBox Control As we saw earlier the Image Property can be set to a graphic image of some sort The flag images in Tutorial 2-16 are clickable The click event can be handled by code to take whatever action is desired Chapter 2 - Slide 40

PictureBox Click Event code When PictureBox picusa is clicked, the lblmessage text property is set to display United States of America Private Sub picusa_click( ) Handles picusa.click ' Display United States of America. lblmessage.text = "United States of America" End Sub Chapter 2 - Slide 41

Section 2.7 USING VISUAL STUDIO HELP Learn to use the Visual Studio Help System Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Accessing the Help System You access the Visual Studio Documentation and the MSDN library by clicking Help on the menu bar. Chapter 2 - Slide 43

Context-Sensitive Help (F1 Key) Displays information about whatever feature the user is currently focused on For example: Click on a Button control Press F1 Help explains all about the Button control Click on a Label control Press F1 Help explains all about the Label control Chapter 2 - Slide 44

Section 2.8 DEBUGGING YOUR APPLICATION At some point, most applications contain bugs (errors) that prevent the application from operating properly. In this section, you learn fundamental debugging techniques. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Compile Errors These are errors in the syntax (form) of your program Visual Basic will inform you of these errors as soon as the code is entered The area of the error will be underlined with a jagged blue line A description of the error will be given in the Error List window Display this window by selecting Error List from the View menu option Chapter 2 - Slide 46

Runtime Errors Some errors occur as your program runs These are different from syntax errors which occur as the code is entered by the programmer Runtime errors occur when Visual Basic attempts to perform an operation that cannot be executed Chapter 2 - Slide 47