c2.ppt

download c2.ppt

of 62

Transcript of c2.ppt

  • 8/9/2019 c2.ppt

    1/62

    2009 Pearson Education, Inc. All rights res erved .

    1

    2

    2Dive Into

    Visual C# 2008Express

  • 8/9/2019 c2.ppt

    2/62

    2009 Pearson Education, Inc. All rights res erved .

    2

    Seeing is believing.

    Proverb

    Form ever follows function. Louis Henri Sullivan

    Intelligence is the faculty of making artificialobjects, especially tools to make tools.

    Henri-Louis Bergson

  • 8/9/2019 c2.ppt

    3/62

    2009 Pearson Education, Inc. All rights res erved .

    3

    OBJECTIVES

    In this chapter you will learn!he "asics o# the $isual %tudio Integrated&evelop'ent Environ'ent (I&E) that assistsyou in writing, running and de"ugging your *+progra's.$isual %tudio s help #eatures.

    ey co''ands contained in the I&E s 'enusand tool"ars.!he purpose o# the various -inds o# windowsin the $isual %tudio 200 I&E.

  • 8/9/2019 c2.ppt

    4/62

    2009 Pearson Education, Inc. All rights res erved .

    /

    OBJECTIVES

    hat visual progra''ing is and how itsi'pli#ies and speeds progra' develop'ent.!o create, co'pile and e ecute a si'ple *+progra' that displays te t and an i'age usingthe $isual %tudio I&E and the techni ue o#visual progra''ing.

  • 8/9/2019 c2.ppt

    5/62

    2009 Pearson Education, Inc. All rights res erved .

    2.1 Intro u!tion

    2.2 Overvie" o t$e Visual Stu io 2008 IDE

    2.% &enu Bar an Tool'ar

    2.( )avi*atin* t$e Visual Stu io IDE

    2.+ ,sin* -elp

    2. ,sin* Visual /ro*ra in* to Create aSi ple /ro*ra t$at Displa s Text anan I a*e

  • 8/9/2019 c2.ppt

    6/62

    2009 Pearson Education, Inc. All rights res erved .

    4

    2.1 Intro u!tion

    Visual Studio 2008 is Microsoft 5s IntegratedDevelopment Environment (IDE) for various .NET

    programming languages. Visual Studio allo s !ou to drag and drop predefined

    components into place 6 a tec"ni#ue called visualprogramming .

  • 8/9/2019 c2.ppt

    7/62 2009 Pearson Education, Inc. All rights res erved .

    7

    2.2 Overvie" o t$e Visual Stu io 2008IDE

    T"e follo ing e$amples use Microsoft Visual C# 2008 Express Edition .

    %ull versions of Visual Studio &'' include support forot"er languages.

  • 8/9/2019 c2.ppt

    8/62 2009 Pearson Education, Inc. All rights res erved .

    Select Start > All Programs > Microsoft VisualC# 2008 Express Edition . T"e Start Page displa!s (%ig. &. ).

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

    4i*. 2.1 5 Start Page in $isual *+ 200 E press Edition.

    New Project button

    Start Page tab

    Toolbox tab collapsible window Start Page links Empty Solution Explorer (no projects open)

  • 8/9/2019 c2.ppt

    9/62 2009 Pearson Education, Inc. All rights res erved .

    9

    The Start Page contains a list o !"# resourcesand $eb-based resources.

    Recent Pro ects contains recentl% modi iedpro&ects.

    !etting Started ocuses on using the !"# orcreating programs' learning Visual () and connectingto the developer communit%.

    Visual C# Express "eadlines and MS $% Visual C# Express Edition provide in ormationabout programming in Visual ().

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

  • 8/9/2019 c2.ppt

    10/62 2009 Pearson Education, Inc. All rights res erved .

    10

    *ou can +ro se t"e e+ using t"e IDE 5s internal $ebbro$ser . Select Vie& > 't(er )indo&s > )e* +ro&ser . ,e#uest a e+ page +! entering its -, into t"e location +ar

    (%ig. &.&).

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

    Re uested web page(!R" inlocation bar drop#down)

    Selected tab $or re uestedweb page

    4i*. 2.2 5 &isplaying a we" page in $isual %tudio.

  • 8/9/2019 c2.ppt

    11/62 2009 Pearson Education, Inc. All rights res erved .

    11

    / pro&ect is a group of related files0 suc" as t"e codefiles and an! images t"at ma1e up a program.

    Solutions contain one ore more pro2ects.

    To +egin programming in Visual 340 select ,ile * $e& Pro ect

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

  • 8/9/2019 c2.ppt

    12/62 2009 Pearson Education, Inc. All rights res erved .

    12

    T"e $e& Pro ect dialog (%ig. &.5) displa!s. Templates are pro2ect t!pes users can create in

    Visual 34. / +indo$s Form s application e$ecutes it"in a 6indo s

    operating s!stem and "as a graphical user inter ace , ! / .

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

    4i*. 2.% 5 $e& Pro ect dialog.

    %isual &' indows FormsApplication (selected)

    e$ault project name(pro*ided by %isual Studio)

    escription o$ selectedproject (pro*ided by%isual Studio)

  • 8/9/2019 c2.ppt

    13/62 2009 Pearson Education, Inc. All rights res erved .

    13

    3lic1 '- to displa! t"e IDE in esign vie$ (%ig. &.7)0 "ic" contains features to create programs.

    T"e gra! rectangle (called a Form ) represents t"emain indo of t"e application.

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

  • 8/9/2019 c2.ppt

    14/62 2009 Pearson Education, Inc. All rights res erved .

    1/

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

    +cti*e tab

    4i*. 2.( 5 esign view o# the I&E.

    Tabs ,enu ,enu bar Solution Explorer window

    Properties windowForm ( indows -orms application)

  • 8/9/2019 c2.ppt

    15/62 2009 Pearson Education, Inc. All rights res erved .

    1

    %igure &.8 s"o s "ere t"e Form 9s name can +e modifiedin t"e Properties indo .

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

    4i*. 2.+ 5 !e t"o control #or 'odi#ying a property in the $isual %tudio I&E.

    Text box (displaying t.e Form 9s name/Form1 ) w.ic. can be modi0ed

    14

  • 8/9/2019 c2.ppt

    16/62 2009 Pearson Education, Inc. All rights res erved .

    14

    %igure &.: s"o s a dialog in "ic" a control9s font properties can +e modified.

    2.2 Overvie" o t$e Visual Stu io 2008IDE Cont.3

    4i*. 2. 5 &ialog #or 'odi#ying a control5s #ont properties in the $isual %tudio I&E.

    12 button

    &ancel button

    17

  • 8/9/2019 c2.ppt

    17/62 2009 Pearson Education, Inc. All rights res erved .

    17

    2.% &enu Bar an Tool'ar Cont.3

    3ommands for managing t"e IDE are contained in menus on t"e menu bar of t"e IDE (%ig. &.;).

    T"e set of menus displa!ed depends on "at !ou arecurrentl! doing in t"e IDE.

    Menus contain groups of related menu items t"at causet"e IDE to perform specific actions.

    4i*. 2.6 5 $isual %tudio 'enu "ar.

    1

  • 8/9/2019 c2.ppt

    18/62 2009 Pearson Education, Inc. All rights res erved .

    1

    4i*. 2.8 5 %u''ary o# $isual %tudio 200 I&E 'enus.

    2.% &enu Bar an Tool'ar Cont.3

    19

  • 8/9/2019 c2.ppt

    19/62 2009 Pearson Education, Inc. All rights res erved .

    19

    2.% &enu Bar an Tool'ar Cont.3

    4i*. 2.7 5 %tandard $isual %tudio tool"ar.

    NewProject

    1pen

    Sa*e +ll

    &opy

    !ndo

    Na*igate3ackward

    Start

    Solution&on0gurations

    +dd New4tem

    Sa*e &ut Paste Redo Na*igate-orward

    Solution Plat$orms -indSolutionExplorer

    1bject3rowser

    Start Page

    ocument1utline

    Toolbo xPropertiesindow

    -ind in -iles

    20

  • 8/9/2019 c2.ppt

    20/62

    2009 Pearson Education, Inc. All rights res erved .

    20

    2.% &enu Bar an Tool'ar Cont.3

    *ou can add more tool+ars +! selecting Vie& > .ool*ars (%ig. &. ').

    4i*. 2.10 5 Adding the +uild tool"ar to the I&E.

    +dditional toolbarsappear .ere

    21

  • 8/9/2019 c2.ppt

    21/62

    2009 Pearson Education, Inc. All rights res erved .

    21

    2.% &enu Bar an Tool'ar Cont.3

    Some icons contain a do n arro t"at displa!s relatedcommands (%ig. &. ).

    4i*. 2.11 5 I&E tool"ar icon showing additional co''ands.

    Toolbar

    own arrow indicatesadditional commands

    22

  • 8/9/2019 c2.ppt

    22/62

    2009 Pearson Education, Inc. All rights res erved .

    22

    2.% &enu Bar an Tool'ar Cont.3

  • 8/9/2019 c2.ppt

    23/62

    2009 Pearson Education, Inc. All rights res erved .

    23

    2.( )avi*atin* t$e Visual Stu io IDE

    T"e IDE provides indo s for accessing pro2ect files andcustomi=ing controls. T"ese indo s can +e accessed via t"e tool+ar icons

    (%ig. &. 5) or t"e Vie& menu.

    4i*. 2.1% 5 !ool"ar icons #or $isual %tudio windows.

    Solution

    Explorer

    Properties window1bject3rowser

    Toolbox

    2/

  • 8/9/2019 c2.ppt

    24/62

    2009 Pearson Education, Inc. All rights res erved .

    2/

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    6"en auto-hide is ena+led0 a ta+ appears along t"e edgeof t"e IDE indo (%ig. &. 7).

    4i*. 2.1( 5 Auto8hide #eature de'onstration.

    4con $or .idden window(auto#.ide enabled)

    2

  • 8/9/2019 c2.ppt

    25/62

    2009 Pearson Education, Inc. All rights res erved .

    2

    2.( )avi*atin* t$e Visual Stu io IDECont.3

  • 8/9/2019 c2.ppt

    26/62

    2009 Pearson Education, Inc. All rights res erved .

    24

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    To disa+le auto>"ide and 1eep t"e indo open0 clic1 t"e pinicon in t"e indo 9s upper>rig"t corner. 6"en a indo is ?pinned do n0@ t"e pin icon is vertical

    (%ig. &. :). Toolbox ?pinned down @%ertical orientation $or pin iconw.en window is pinned down

    4i*. 2.1 5 &isa"ling auto8hide ( pinning down: a window).

    27

  • 8/9/2019 c2.ppt

    27/62

    2009 Pearson Education, Inc. All rights res erved .

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    2/ /1 Solution Explorer T"e Solution Explorer indo (%ig. &. ;) provides

    access to all of a solution9s files. T"e solution9s startup pro&ect runs "en !ou select e*ug

    > Start e*ugging . T"e file t"at corresponds to t"e Form is named Form1.cs .

    Visual 34 files use t"e .cs file>name e$tension.

    4i*. 2.16 5 Solution Explorer with an open pro;ect.

    S.ow +ll -iles icon

    Toolbar

    Startup project

    2

  • 8/9/2019 c2.ppt

    28/62

    2009 Pearson Education, Inc. All rights res erved .

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    3lic1ing t"e S(o& All ,iles icon displa!s all t"e filesin t"e solution (%ig. &. ).

    4i*. 2.18 5 Solution Explorer showing plus "o es and 'inus "o es #or e panding andcollapsing the tree to reveal or hide pro;ect #iles, respectively.

    Plus box

    ,inus box

    Pre*iously

    .idden $olders

    29

  • 8/9/2019 c2.ppt

    29/62

    2009 Pearson Education, Inc. All rights res erved .

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    3lic1 a plus +o$ to displa! grouped items (%ig. &. A)

    4i*. 2.17 5 Solution Explorer e panding the /roperties #ile a#ter you clic- its plus"o .

    ,inus box indicatest.at t.e 0le or $older

    is expanded (c.anged

    $rom plus box)

    30

  • 8/9/2019 c2.ppt

    30/62

    2009 Pearson Education, Inc. All rights res erved .

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    3lic1 t"e minus +o$ to collapse t"e tree from its e$pandedstate (%ig. &.&').

    4i*. 2.20 5 Solution Explorer collapsing all #iles a#ter you clic- any 'inus "o es.

    Plus boxes indicatet.at t.e 0le or $older

    is collapsed (c.anged$rom minus box

    31

  • 8/9/2019 c2.ppt

    31/62

    2009 Pearson Education, Inc. All rights res erved .

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    2/ /2 .ool*ox

    T"e .ool*ox contains iconsrepresenting controls used to

    customi=e Form s (%ig. &.& ).

    T"e .ool*ox groups t"e pre+uilt controls intocategories.

    7roup names

    &ontrols

    4i*. 2.21 5 .ool*ox window displaying controls #or the Common Controls group.

    32

  • 8/9/2019 c2.ppt

    32/62

    2009 Pearson Education, Inc. All rights res erved .

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    2/ /2 .ool*ox To displa! t"e Properties indo 0 select Vie&

    > Properties )indo& . T"e Properties $indo$ allo s !ou to modif! a

    control9s properties visuall!0 it"out riting code(%ig. &.&&).

    33

  • 8/9/2019 c2.ppt

    33/62

    2009 Pearson Education, Inc. All rights res erved .

    2.( )avi*atin* t$e Visual Stu io IDECont.3

    4i*. 2.22 5 Properties window showing the description o# the selected property.

    Property *alues

    Properties

    escription

    &ategori6ed icon

    +lp.abetical icon

    &omponentselection drop#down list

    Toolbar

    Scrollbar

    Scrollbox

    3/

  • 8/9/2019 c2.ppt

    34/62

    2009 Pearson Education, Inc. All rights res erved .

    4i*. 2.2% 5 "elp 'enu co''ands.

    T"e Help menu commands are summari=ed in %ig. &.&5.

    2.+ ,sin* -elp

    3

  • 8/9/2019 c2.ppt

    35/62

    2009 Pearson Education, Inc. All rights res erved .

    2.+ ,sin* -elp Cont.3

    (onte t-sensitive help displa!s relevant "elp articlesrat"er t"an a generali=ed list (%ig. &.&7). To use conte$t>sensitive "elp0 clic1 an item0 t"en press t"e F1 1e!.

    4i*. 2.2( 5

  • 8/9/2019 c2.ppt

    36/62

    2009 Pearson Education, Inc. All rights res erved .

    2.+ ,sin* -elp Cont.3

    Select .ools > 'ptions Ma1e sure t"at t"e S(o& all settings c"ec1+o$

    is c"ec1ed (%ig. &.&8). Select "elp on t"e left0 t"en locate t"e S(o& "elp

    using% drop>do n list. External "elp Vie&er displa!s articles in a separate

    indo

    3ntegrated "elp Vie&er displa!s a "elp articleinside t"e IDE.

    37

  • 8/9/2019 c2.ppt

    37/62

    2009 Pearson Education, Inc. All rights res erved .

    2.+ ,sin* -elp Cont.3

    4i*. 2.2+ 5 'ptions dialog displaying -elp settings.

    S.ow 5elp using drop#down list5elp options selected

    S.ow all settings c.eck box

    3

    l

  • 8/9/2019 c2.ppt

    38/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e

    Visual 34 "as pree$isting controls used to +uild and customi=e programs (%ig. &.&:).

    / Label contains descriptive te$t.

    / PictureBox displa!s an image0 suc" as t"e Deitel +ugmascot.

    4i*. 2.2 5 %i'ple progra' e ecuting.

    Label control

    PictureBox control

    39

    2 i i l i

  • 8/9/2019 c2.ppt

    39/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    Select ,ile > $e& Pro ect and create a ne)indo&s ,orms Application (%ig. &.&;).

    Name t"e pro2ect ASimpleProgram and clic1 '- .

    4i*. 2.26 5 $e& /ro e!t dialog.

    Type t.e project name Template types

    /0

    2 i * Vi l / * i *

  • 8/9/2019 c2.ppt

    40/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    Select ,ile > Sa4e All to displa! t"e Sa4e Pro ect dialog (%ig. &.& ).

    4i*. 2.28 5 Sa4e Pro ect dialog.

    /1

    2 i * Vi l / * i *

  • 8/9/2019 c2.ppt

    41/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    3lic1 t"e +ro&se +utton0 "ic" opens t"ePro ect 5ocation dialog (%ig. &.&A).

    Navigate t"roug" t"e directories and select one in"ic" to place t"e pro2ect.

    /2

    2 i * Vi l / * i *

  • 8/9/2019 c2.ppt

    42/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    4i*. 2.27 5 %etting the pro;ect location in the Pro ect 5ocation dialog.

    Selected project location

    &lick to set projectlocation

    /3

    2 i * Vi l / * i *

  • 8/9/2019 c2.ppt

    43/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    3lic1 an! "ere in t"e Form to displa! t"e Form 9s properties in t"e Properties indo .

    3lic1 in t"e te$t+o$ to t"e rig"t of t"e Text propert% +o$ and t!pe ? A Simple Program @ (%ig. &.5').

    4i*. 2.%0 5 %etting the Form 5s Text property in the Properties window.

    Selected property

    Property description

    Name and type o$ control

    Property *alue

    //

    2 i * Vi l / * i * t

  • 8/9/2019 c2.ppt

    44/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

  • 8/9/2019 c2.ppt

    45/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    Select t"e +ottom>rig"t si=ing "andle and drag it do n andto t"e rig"t to ma1e t"e Form larger (%ig. &.5&).

    *ou can also resi=e a Form +! setting its Size propert!.

    4i*. 2.%2 5 >esi=ed Form .

    /4

    2 i * Vi l / * i * t

  • 8/9/2019 c2.ppt

    46/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra Cont.3

    3lic1ing BackColor in t"e Properties indo causes ado n>arro +utton to appear (%ig. &.55). 6"en clic1ed0 t"e arro displa!s ta+s for Custom 0)e*

    and S6stem colors.

    3lic1 t"e Custom tab to displa! t"e palette and select lig"t +lue.

    4i*. 2.%% 5 *hanging the Form 5s BackColor property.

    &urrent color

    own#arrow button

    "ig.t blue

    &ustom palette

    /7

    2 i * Vi l / * i * t

  • 8/9/2019 c2.ppt

    47/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    Cnce !ou select t"e color0 t"e Form 9s +ac1ground c"angesto lig"t +lue (%ig. &.57).

    4i*. 2.%( 5 Form with new BackColor property applied.

    New background color

    /

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    48/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    Dou+le clic1 t"e Label control in t"e .ool*ox to add aLabel (%ig. &.58).

    *ou also can ?drag@ controls from t"e .ool*ox to t"e

    Form .

    4i*. 2.%+ 5 Adding a Label to the Form .

    Label control

    /9

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    49/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    Select t"e Label to ma1e its properties appear in t"eProperties indo (%ig. &.5:).

    Set t"e Label 9sText propert! to )elcome to Visual

    C#7 . T"e AutoSize propert% is set to True0 "ic" allo s t"e

    Label to resi=e to fit its te$t. Set t"e AutoSize propert! to False .

    0

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    50/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    4i*. 2.% 5 *hanging the Label 5s AutoSize property to False .

    AutoSizeproperty

    1

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    51/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    Move t"e Label +! dragging it or +! using t"e left andrig"t arro 1e!s (%ig. &.5;).

    6"en t"e Label is selected0 !ou can also centert"e Label using t"e ,ormat menu.

    4i*. 2.%6 5 ?

  • 8/9/2019 c2.ppt

    52/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    To c"ange t"e font of t"e Label 5s te$t0 select t"e Font propert% (%ig. &.5 ).

    6"en t"e ellipsis +utton is clic1ed0 a dialog appears t"at

    provides additional values.

    4i*. 2.%8 5 Properties window displaying the Label 5s properties.

    Ellipsis button

    3

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    53/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra Cont.3

    T"e ,ont dialog (%ig. &.5A) allo s !ou to select t"e fontname0 st!le and si=e.

    -nder ,ont 0 select Segoe 3 . -nder Si9e 0 select 2 points and clic1 '- .

    ,esi=e t"e Label if it9s not large enoug" to "old t"e te$t.

    4i*. 2.%7 5 ,ont dialog #or selecting #onts, styles and si=es.

    -ont sample

    &urrent $ont

    /

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    54/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    Select t"e Label 9sTextAlign propert! (%ig. &.7'). Set t"e Text Align propert! to MiddleCenter .

    4i*. 2.(0 5 *entering the Label 5s te t.

    Text alignmentoptions

    ,iddle&enteralignment option

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    55/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin* Visual /ro*ra in* toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    ocate t"e PictureBox in t"e .ool*ox and add it tot"e Form (%ig. &.7 ).

    4i*. 2.(1 5 Inserting and aligning a PictureBox .

    !pdatedLabel

    PictureBox

    4

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    56/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin Visual /ro ra in toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    3lic1 t"e PictureBox to displa! its properties in t"eProperties indo (%ig. &.7&).

    T"e Image propert% displa!s a previe of t"e image0 if

    one e$ists.

    4i*. 2.(2 5 mage property o# the PictureBox .

    mage property *alue(no image selected)

    7

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    57/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin Visual /ro ra in toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    3lic1 t"e ellipsis +utton to displa! t"e Select Resource dialog (%ig. &.75).

    3lic1 t"e 3mport +utton to +ro se for t"e image to

    insert ( bug.png )

    4i*. 2.(% 5 Select Resource dialog to select an i'age #or the PictureBox .

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    58/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin Visual /ro ra in toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    In t"e dialog t"at appears0 locate t"e image file0 select itand clic1 '- (%ig. &.77).

    3lic1 '- to place t"e image in !our program.

    4i*. 2.(( 5 Select Resource dialog displaying a preview o# selected i'age.

    4mage 0le name

    9

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    59/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin Visual /ro ra in toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    To si=e t"e image to t"e PictureBox 0 c"ange t"eSizeMode propert% to StretchImage (%ig. &.78).

    4i*. 2.(+ 5 %caling an i'age to the si=e o# the PictureBox .

    SizeModeproperty

    SizeModeproperty set toStretc! mage

    40

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    60/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin Visual /ro ra in toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    ,esi=e t"e PictureBox 0 ma1ing it larger (%ig. &.7:). Select ,ile > Sa4e All to save t"e entire solution.

    4i*. 2.( 5 PictureBox displaying an i'age.

    Newlyinsertedimage

    41

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    61/62

    2009 Pearson Education, Inc. All rights res erved .

    2. ,sin Visual /ro ra in toCreate a Si ple /ro*ra t$at Displa sText an an I a*e Cont.3

    In run mode 0 t"e program is e$ecuting0 and some featuresare disa+led (%ig. &.7;).

    4i*. 2.(6 5 @uilding a solution.

    3uild menu

    42

    2 sin* Visual /ro*ra in* to

  • 8/9/2019 c2.ppt

    62/62

    2. ,sin Visual /ro ra in toCreate a Si ple /ro*ra Cont.3

    Select e*ug > Start e*ugging to e$ecute t"e program (%ig. &.7 ).

    Running program

    Form

    4 E displays text Running/ w.ic.signi0es t.at t.e program is executing

    &lose box