visualbasic lecture3.pdf

Upload: aseret423

Post on 02-Jun-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 visualbasic lecture3.pdf

    1/23

    Copyright 2011 Pearson Addison-Wesley

    Addison Wesley

    is an imprint of

    2011 Pearson Addison-Wesley. All rights reserved.

    Chapter 2

    Creating Applications with

    Visual Basic

  • 8/10/2019 visualbasic lecture3.pdf

    2/23

    Copyright 2011 Pearson Addison-Wesley

    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 ou create our !irst Visual

    Basic application:

    a window that displas a map and road

    directions to a hotel. In the

    rocess ou learn how to lace controls on

  • 8/10/2019 visualbasic lecture3.pdf

    3/23

    Copyright 2011 Pearson Addison-Wesley

    "e!ine #hat the Application is $o

    "o %urpose: "ispla a map to the &ighlander&otel

    Input: 'one %rocess: "ispla a !orm

    (utput: "ispla on the !orm a graphic image

    showing a map

    Chapter 2 ) Slide *

  • 8/10/2019 visualbasic lecture3.pdf

    4/23

    Copyright 2011 Pearson Addison-Wesley

    Visuali+e the Application and "esign Its

    ,ser Inter!ace

    Below is a s-etch o! the applications !orm

    Chapter 2 ) Slide /

  • 8/10/2019 visualbasic lecture3.pdf

    5/23

  • 8/10/2019 visualbasic lecture3.pdf

    6/23

    Copyright 2011 Pearson Addison-Wesley

    "e!ine 6elevant %ropert Values !or 7ach

    Control

    Form

    'ame: Form1

    $e4t: 3"irections3 abel

    'ame: abel1

    $e4t: 3"irections to the &ighlander &otel3

    $e4tAlign: 8iddleCenter

    Font: 8icroso!t sans seri!9 bold9 1 point Chapter 2 ) Slide <

  • 8/10/2019 visualbasic lecture3.pdf

    7/23

    Copyright 2011 Pearson Addison-Wesley

    Create the Forms and (ther Controls ,sing

    Visual Basic

    7stablish the Form and set its $e4t propert

    Add a abel control

    %osition and resi+e it on the !orm

    Set $e4t9 $e4tAlign9 and Font properties

    Add a %ictureBo4 control

    %osition and resi+e it on the !orm

    Set Image propert to displa &otel8ap.;pg

    6un the application Chapter 2 ) Slide =

  • 8/10/2019 visualbasic lecture3.pdf

    8/23

    Copyright 2011 Pearson Addison-Wesley

    "esign 8ode9 6un 8ode9 and Brea- 8ode

    Visual Basic has three modes in which it

    operates:

    "esign 8ode

    the mode in which ou create the application

    also -nown as design time

    6un 8ode e4ecutes the application in the Visual Studio

    environment

    also -nown as run time

    Chapter 2 ) Slide

  • 8/10/2019 visualbasic lecture3.pdf

    9/23

    Copyright 2011 Pearson Addison-Wesley

    %ro;ect (rgani+ation (n "is-

    ,ser creates a new pro;ect in Visual Studio

    A solution and a !older are created at the same

    time with the same name as the pro;ect

    $he pro;ect belongs to the solution

    8ultiple pro;ects can be included in a solution

    $he !older stores !iles related to the pro;ectincluding:

    A solution !ile 0.sln

    A pro;ect !ile 0.vbpro; Chapter 2 ) Slide >

  • 8/10/2019 visualbasic lecture3.pdf

    10/23

    Copyright 2011 Pearson Addison-Wesley

    (pening an 74isting %ro;ect

    ,se 6ecent %ro;ects list on Start %age

    %rovided it hasnt been moved or deleted

    ,se (pen %ro;ect button on Start %age $hen browse using (pen %ro;ect dialog bo4

    ,se (pen %ro;ect option on File menu

    $hen browse using (pen %ro;ect dialog bo4

    Chapter 2 ) Slide1?

  • 8/10/2019 visualbasic lecture3.pdf

    11/23

    Copyright 2011 Pearson Addison-Wesley

    %roperties #indow

    ,sed to view and modi! the propert values

    o! a given ob;ect

    $wo views o! the properties are available: Alphabetic 0across all properties

    Categori+ed 0groups properties b logical use

    Chapter 2 ) Slide11

  • 8/10/2019 visualbasic lecture3.pdf

    12/23

    Copyright 2011 Pearson Addison-Wesley

    Addison Wesley

    is an imprint of

    2011 Pearson Addison-Wesley. All rights reserved.

    Section 2.2

    Focus on problem Solving:6esponding to 7vents

    An application responds to events9 such as

    mouse clic-s and -eboard input9 b e4ecuting code -nown

    as event handlers.

    In this section9 ou write event handlers !or

  • 8/10/2019 visualbasic lecture3.pdf

    13/23

    Copyright 2011 Pearson Addison-Wesley

    8odi! the DirectionsApplication

    $he &ighlander &otel manager would li-e ou to add

    the !ollowing items to the application:

    A abel containing the written directions

    A Button to displa the directions

    A Button to e4it the application

    Chapter 2 ) Slide1*

  • 8/10/2019 visualbasic lecture3.pdf

    14/23

    Copyright 2011 Pearson Addison-Wesley

    Controls to be Added

    Control Type Control Name Description

    abel lbl"irections "isplas written directions

    to the hotel

    Button btn"ispla"irections #hen clic-ed9 causeslbl"ispla"irections te4t

    to appear on the !orm

    Button btn74it Stops the application

    when clic-ed

    Chapter 2 ) Slide1/

  • 8/10/2019 visualbasic lecture3.pdf

    15/23

  • 8/10/2019 visualbasic lecture3.pdf

    16/23

    Copyright 2011 Pearson Addison-Wesley

    $he Code #indow

    "ouble)clic-ing a control in design mode:

    opens the code window

    creates a code template !or the controls eventhandler where ou !ill in the code !or the event

    Chapter 2 ) Slide1