Chapter Creating Applications With Visual Basic 2.

Slides:



Advertisements
Similar presentations
Creating Applications With Visual Basic
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Chapter 1: An Introduction to Visual Basic 2012
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Chapter 2 –Visual Basic, Controls, and Events
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Chapter Creating Applications With Visual Basic 2.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Copyright © 2014 Pearson Education, Inc. Chapter 2 Creating Applications with Visual Basic.
110-C1 Chapter 2 of the text: _ text boxes, group boxes, check boxes, radio buttons, picture boxes _ defining access keys tab sequence setting the focus.
Chapter 2 –Visual Basic, Controls, and Events
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 1: Chapter 2: Slide 1 Unit 1 Introduction to Programming Using VB.NET Chapter.
Visual Basic Chapter 1 Mr. Wangler.
05/09/ Introducing Visual Basic Sequence Programming.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IE 411/511: Visual Programming for Industrial Applications
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 2 More Controls Programming in C#. NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
CSCI Chapter 2 Creating Application with Visual Basic Instructor: Bindra Shrestha University of Houston – Clear Lake.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
 2009 Pearson Education, Inc. All rights reserved Dive Into ® Visual C# 2008 Express.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 2 Creating Applications With Visual Basic.NET.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Copyright © 2014 Pearson Education, Inc. Chapter 2 Creating Applications with Visual Basic.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Introduction to Visual Basic.NET Your First Visual Basic.NET Application.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
OBJECTIVES: To open an existing Project called HelloWorld. To learn how set properties using the property window and how to set them in the code. Chapter.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 2 Creating Applications with Visual Basic.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
More User Interface Controls User interface controls are located in the toolbox. Click the +/- signs to open/ close the different tabs of the tollbox.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 4 Designing the Inventory Application Introducing TextBox es and Button s.
Chapter 2 More Controls Programming in C#. NET Objectives Use text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 2 Creating Applications with Visual Basic.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Chapter 1: An Introduction to Visual Basic .NET
Chapter 2: The Visual Studio .NET Development Environment
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
3.01 Apply Controls Associated With Visual Studio Form
Visual studio 2010 SENG 403, Tutorial 2 SENG Winter 2011.
Introduction to the Visual C# 2005 Express Edition IDE
Creating Applications with Visual Basic
Chapter 2 – Introduction to the Visual Studio .NET IDE
STARTING OUT WITH Visual Basic 2008
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

Chapter Creating Applications With Visual Basic 2

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 2 Introduction Develop your first application: Display a map and written directions to the Highlander Hotel Use a form with Labels Use a PictureBox control Use Buttons Write an event procedure

Building the Hotel Directions Application 2.1 In This Section You Create Your First Visual Basic Application: a Window That Displays a Map and Road Directions to a Hotel

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 4 Define What the Program is To Do Purpose: Display a map to the Highlander Hotel Input: None Process: Display a form Output: Display a graphic image showing a map on the form

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 5 Visualize and Design the User Interface Below is a sketch of the form to be shown

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 6 List the Controls Needed Control TypeControl NameDescription FormForm1A small form that will serve as (Default Name)the window onto which the other controls will be placed LabelLabel1Displays the message (Default Name)"Directions to the Highlander Hotel" PictureBoxPictureBox1Displays the graphic image (Default Name)showing the map to the hotel

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 7 Define Control Relevant Property Values 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 8 Use VB to Create the Application 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 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)

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 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)

Responding to Events 2.2 An Application Responds to Events, Such As Mouse Clicks and Keyboard Input, by Executing Code Known As Event Procedures Write the Event Procedures for the Directions Application

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Augment the Hotel Application Now the hotel owner wants to add an option to view written directions:

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Controls to be Added Control TypeControl NameDescription LabellblDirectionsDisplays written directions to the hotel ButtonbtnDisplayDirectionsWhen clicked, causes lblDisplayDirections text to appear on the form ButtonbtnExitStops the application when clicked

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Control Properties Label: Name: lblDirections Text: "Traveling on I-89, take…“ Visible: False Button: Name: btnDisplayDirections Text: "Display Directions“ Button: Name: btnExit Text: "Exit"

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Method btnDisplayDirections_Click Private Sub btnDisplayDirections_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnDisplayDirections.Click ' Make the directions visible lblDirections.Visible = True End Sub Line Continuation Mark Name of the event the procedure responds to Name of the control that owns the event procedure Marks the beginning of this event procedure Makes the control lblDirections visible: Assigns the value True to the Visible Property of the lblDirections control. Event handled by this procedure

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Syntax for Referring to the Value of a Control's Property 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Syntax for an 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Method btnExit_Click Private Sub btnExit_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnExit.Click ' End the application by closing the window Me.Close() End Sub Line Continuation Mark Name of the event the procedure responds to Name of the control that owns the event procedure Marks the beginning of this event procedure Closes the current form, referred to as Me, and ends the program Event handled by this procedure

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Additional Properties Color properties for a control: BackColor: Sets the background (fill) color ForeColor: Sets the foreground (text) color 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

Modifying the Text Property With Code 2.3 Quite Often, You Will Need to Change a Control’s Text Property With Code This Is Done With an Assignment Statement

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Modifying the Text Property in Code Private Sub btnFeet_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) 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

The AutoSize, BorderStyle, and TextAlign Properties 2.4 The Label Control’s AutoSize Property Allows a Label to Change Size Automatically to Accommodate the Amount of Text in its Text Property The BorderStyle Property Allows You to Set a Border Around a Label Control

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide AutoSize Property for Labels 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide BorderStyle Property for Labels 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide TextAlign Property for Labels The value of TextAlign establishes the alignment ( or justification) or the text: TopLeft TopCenter TopRight The assignment statement below forces the text of lblTitle to appear in the middle center of the label lblTitle.TextAlign = ContentAlignment.MiddleCenter MiddleLeft MiddleCenter MiddleRight BottomLeft BottomCenter BottomRight

Clickable Images 2.5 Controls Other Than Buttons Have Click Event Procedures PictureBox Controls Can Respond to Mouse Clicks

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 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(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles picUSA.Click ' Display the country name lblMessage.Text = "United States of America" End Sub

Using Visual Basic Help 2.6 Learn to Use the Visual Basic Help System

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Dynamic Help Dynamic Help provides context sensitive help information relevant to the operation you are currently performing The Properties window and Dynamic Help window may hide each other since they occupy the same area of the screen If one of these windows is hidden, click the tab at the bottom to select which to view

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Help Menu The usual categories of Help you are probably accustomed to in Microsoft applications Contents… Index… Search… Are available through this window also

Debugging Your Application 2.7 At Some Point, Most Applications Contain Bugs, or Errors That Prevent the Application From Operating Properly

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Types of Errors: Compile Errors These are errors in the syntax (form) of your program Visual Basic will inform you of these as soon as they are found The area of the error will be underlined with a jagged blue line A description of the error will be given in the Task List window Display the Task List window by selecting Error List from the View menu option

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Types of Errors: Runtime Errors These errors occur as your program runs Runtime errors create incorrect results but do not prevent your program from running Visual Basic will detect some of these and inform you about them Others you must detect yourself Always carefully check the operation of your program to be sure that it operates as required