c15.ppt

download c15.ppt

of 146

Transcript of c15.ppt

  • 7/26/2019 c15.ppt

    1/146

    2009 Pearson Education, Inc. All rights reserved.

    1

    15

    15Graphical UserInterfaces with

    Windows Forms:Part 2

  • 7/26/2019 c15.ppt

    2/146

    2009 Pearson Education, Inc. All rights reserved.

    2

    I claim not to have controlled events, but confessplainly that events have controlled me.

    Abraham Lincoln

    Capture its reality in paint! Paul Czanne

    An actor entering through the door, youve gotnothing. But if he enters through the window,youve got a situation.

    Billy Wilder

    But, soft! what light through yonder window breaksIt is the east, and uliet is the sun!

    William Shakespeare

  • 7/26/2019 c15.ppt

    3/146

    2009 Pearson Education, Inc. All rights reserved.

    3

    OBJE!I"E#

    In this chapter you will learn !o create "enus, ta##ed windows and "ultiple

    docu"ent inter$ace %&'I( progra"s.

    !o use the ListViewand TreeViewcontrols $or

    displaying in$or"ation. !o create hyperlin)s using the LinkLabelcontrol.

    !o display lists o$ in$or"ation in ListBoxandComboBoxcontrols.

    !o input date and ti"e data with theDateTimePicker.

    !o create custo" controls.

  • 7/26/2019 c15.ppt

    4/146

    2009 Pearson Education, Inc. All rights reserved.

    *

    15$1 Introd%ction

    15$2 &en%s

    15$' MonthCalendarontrol

    15$( DateTimePickerontrol

    15$5 LinkLabelontrol

    15$) ListBoxontrol

    15$* CheckedListBoxontrol

    15$+ ComboBoxontrol

    15$, TreeViewontrol

    15$1- ListViewontrol

    15$11 TabControlontrol

    15$12 &%ltiple .oc%ment Interface /&.I0 Windows15$1' "is%al Inheritance

    15$1( User.efined ontrols

  • 7/26/2019 c15.ppt

    5/146

    2009 Pearson Education, Inc. All rights reserved.

    +

    15$1 Introd%ction

    Visual Studio provides a large set of GUI components. Visual Studio also enables you to design custom

    controls and add them to the ToolBox

  • 7/26/2019 c15.ppt

    6/146

    2009 Pearson Education, Inc. All rights reserved.

    15$2 &en%s Menusprovide groups of related commands (Fig. 1.1!.

    "enus organi#e commands $ithout %cluttering& the GUI.

    Fi$ 15$13&enus, su#"enus and "enu ite"s.

    Checked menu item

    Submenu

    Separator bar

    Shortcut key Disabled commandsMenu Menu items

    Menu icons

  • 7/26/2019 c15.ppt

    7/1462009 Pearson Education, Inc. All rights reserved.

    -

    15$2 &en%s /ont$0

    'o create a menu open the Toolboxand drag a MenuStrip

    control onto the Form. 'o add menu items to the menu clic) the TypeHereTextBox

    (Fig. 1.*! and type the menu item+s name.

    Fi$ 15$23Editing "enus in isual /tudio.

    MenuStripicon

    Type menu namein TextBox

    Main menubar

  • 7/26/2019 c15.ppt

    8/1462009 Pearson Education, Inc. All rights reserved.

    15$2 &en%s /ont$0 ,fter you press theEnter)ey the menu item is added.

    "ore TypeHereTextBoxes allo$ you to add more items(Fig.1.-!.

    Fi$ 15$'3Adding ToolStripMenuItemsto a MenuStrip.

    Place & characterbefore a letter

    tounderline it in

    the menu, sothe

    character canbe

    used as anaccess

    shortcut

    TextBoxes for

    adding itemsto

    the menu

  • 7/26/2019 c15.ppt

    9/1462009 Pearson Education, Inc. All rights reserved.

    9

    15$2 &en%s /ont$0

    "enus can haveAlt)ey shortcuts $hich are accessedby pressingAltand the underlined letter.

    'o ma)e the Filemenu item have a )ey shortcut type&File.

    'he letter Fis underlined to indicate that it is ashortcut.

  • 7/26/2019 c15.ppt

    10/1462009 Pearson Education, Inc. All rights reserved.

    10

    15$2 &en%s /ont$0

    "enu items can have shortcut )eys as $ell (Ctrl ShiftAlt,F1F2

    letter )eys and so on!. 'o add other shortcut )eys set the ShortcutKeysproperty

    (Fig. 1.!.

    Fi$ 15$(3/etting a "enu ite"s shortcut )eys.

    Select key (modier and keycombination species the

    shortcut key for the menuitem

    Setting modierkeys

  • 7/26/2019 c15.ppt

    11/1462009 Pearson Education, Inc. All rights reserved.

    11

    15$2 &en%s /ont$0

    /ou can remove a menu item by selecting it $ith the

    mouse and pressing theDelete)ey.

    "enu items can be grouped by separator bars $hich areinserted by right clic)ing and selecting Insert

    Separatoror by typing -for the te0t of a menu item.

    4ooandFeel O6ser7ation 15$1Buttons can have access shortcuts. Place the &symbolimmediately beore the desired character in the

    Button!s te"t. #o press the button$ the user pressesAlt

    and the underlined character.

  • 7/26/2019 c15.ppt

    12/1462009 Pearson Education, Inc. All rights reserved.

    12

    15$2 &en%s /ont$0

    Visual Studio allo$s you to addTextBoxesandComboBoxesas menu items.

    efore you enter te0t for a menu item you are

    provided $ith a drop2do$n list.

    3lic)ing the do$n arro$ allo$s you to select the type of

    item to add (Fig. 1.!.

    13

  • 7/26/2019 c15.ppt

    13/1462009 Pearson Education, Inc. All rights reserved.

    13

    15$2 &en%s /ont$0

    Fi$ 15$53&enu4ite" options.

    Menu item options

    1*

  • 7/26/2019 c15.ppt

    14/1462009 Pearson Education, Inc. All rights reserved.

    1*

    15$2 &en%s /ont$0

    Fi$ 15$)3MenuStripand ToolStripMenuItemproperties and an event. %Part 1 o$ 2.(

    1+

  • 7/26/2019 c15.ppt

    15/1462009 Pearson Education, Inc. All rights reserved.

    1+

    Fi$ 15$)3MenuStripand ToolStripMenuItemproperties and an event. %Part 2 o$ 2.(

    15$2 &en%s /ont$0

    1

  • 7/26/2019 c15.ppt

    16/146

    2009 Pearson Education,Inc. All rights reserved.

    1

    5utline

    MenuTestorm!cs

    ( 1 of 14 !4ooandFeel O6ser7ation 15$2%t is a convention to place an ellipsis ater the

    name o a menu item &e.'.$ SaveAs...( thatre)uires the user to provide more inormation*

    typically throu'h a dialo'.

    3lass MenuTestForm(Fig. 1.5! creates a simplemenu on a Form.

    1-

  • 7/26/2019 c15.ppt

    17/146

    2009 Pearson Education,Inc. All rights reserved.

    1-

    5utline

    MenuTestorm!cs

    ( * of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part 1 o$ 9.(

    1

  • 7/26/2019 c15.ppt

    18/146

    2009 Pearson Education,Inc. All rights reserved.

    1

    5utline

    MenuTestorm!cs

    ( - of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part 2 o$ 9.(

    'he 86o%tmenu item

    displays a MessageBox$hen clic)ed.

    'he E9itmenu item

    closes the application

    through method #xitofclass $pplication.

    19

  • 7/26/2019 c15.ppt

    19/146

    2009 Pearson Education,Inc. All rights reserved.

    19

    5utline

    MenuTestorm!cs

    ( of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part 3 o$ 9.(

    6ach olormenu item calls

    ClearColorbefore settingits Cecke!property(ma)ing the chec)s mutually

    e0clusive!.

    20

  • 7/26/2019 c15.ppt

    20/146

    2009 Pearson Education,Inc. All rights reserved.

    20

    5utline

    MenuTestorm!cs

    ( of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part * o$ 9.(

    6ach olormenu item calls

    ClearColorbefore setting

    its Cecke!property(ma)ing the chec)s mutually

    e0clusive!.

    21

  • 7/26/2019 c15.ppt

    21/146

    2009 Pearson Education,Inc. All rights reserved.

    21

    5utline

    MenuTestorm!cs

    ( 7 of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part + o$ 9.(

    6ach olormenu item calls

    ClearColorbefore setting itsCecke!property (ma)ing thechec)s mutually e0clusive!.

    6ach Fontmenu item calls

    ClearFontbefore setting its

    Cecke!property (ma)ing thechec)s mutually e0clusive!.

    22

  • 7/26/2019 c15.ppt

    22/146

    2009 Pearson Education,Inc. All rights reserved.

    22

    5utline

    MenuTestorm!cs

    ( 5 of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part o$ 9.(

    6ach Fontmenu

    item calls

    ClearFontbeforesetting its Cecke!

    property (ma)ing the

    chec)s mutually

    e0clusive!.

    23

  • 7/26/2019 c15.ppt

    23/146

    2009 Pearson Education,Inc. All rights reserved.

    23

    5utline

    MenuTestorm!cs

    ( 8 of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part - o$ 9.(

    6ach Fontmenu item calls

    ClearFontbefore setting itsCecke!property (ma)ing thechec)s mutually e0clusive!.

    'he Boldand

    Italicmenu items

    use the bit$ise

    logical e0clusive

    9: operator to

    combine fontstyles.

    2*

  • 7/26/2019 c15.ppt

    24/146

    2009 Pearson Education,Inc. All rights reserved.

    2*

    5utline

    MenuTestorm!cs

    ( ; of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part o$ 9.(

    'he Boldand Italic

    menu items use the

    bit$ise logical

    e0clusive 9: operator

    to combine font styles.

    2+

  • 7/26/2019 c15.ppt

    25/146

    2009 Pearson Education,Inc. All rights reserved.

    2+

    5utline

    MenuTestorm!cs

    ( 14 of 14 !

    Fi$ 15$*6 &enus $or changing te7t $ont and color. %Part 9 o$ 9.(

    a !pplication atstart

    b Changing font to"old

    c !pplication #ith boldfont

    d Changing font to$ed

    e !pplication #ith $edfont

    f Message from !boutmenu item

    2

  • 7/26/2019 c15.ppt

    26/146

    2009 Pearson Education, Inc. All rights reserved.

    15$2 &en%s /ont$0

    #oftware Enineerin O6ser7ation 15$1

    #he mutual e"clusion o menu items is not enorced by

    the MenuStrip$ even +hen the Checkedproperty is

    true. ,ou must pro'ram this behavior.

    2-

  • 7/26/2019 c15.ppt

    27/146

    2009 Pearson Education, Inc. All rights reserved.

    15$' MonthCalendarontrol

    'he MonthCalendarcontrol (Fig. 1.8! displays a monthlycalendar on the Form.

    "ultiple dates can be selected by clic)ing dates on the calendar $hile

    holding do$n the Shift)ey.

    Fi$ 15$+3MontCalen!arcontrol.

    Current day is outlined

    Selected day is highlighted

    2

  • 7/26/2019 c15.ppt

    28/146

    2009 Pearson Education, Inc. All rights reserved.

    15$' MonthCalendarontrol

    Fi$ 15$,3MontCalen!arproperties and an event.

    29

  • 7/26/2019 c15.ppt

    29/146

    2009 Pearson Education, Inc. All rights reserved.

    15$( DateTimePickerontrol

    'he DateTimePickercontrol displays a calendar$hen a do$n arro$ is selected.

    'he DateTimePickercan be used to retrieve dateand time information from the user.

    30

  • 7/26/2019 c15.ppt

    30/146

    2009 Pearson Education, Inc. All rights reserved.

    15$( DateTimePickerontrol

    Fi$ 15$1-3DateTimePickerproperties and an event. %Part 1 o$ 2.(

    31

  • 7/26/2019 c15.ppt

    31/146

    2009 Pearson Education, Inc. All rights reserved.

    15$( DateTimePickerontrol

    Fi$ 15$1-3DateTimePickerproperties and an event. %Part 2 o$ 2.(

    32

  • 7/26/2019 c15.ppt

    32/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Figure 1.11 demonstrates using the

    DateTimePickercontrol to select an item+s

    drop2off time. 'he DateTimePickerhas its Formatproperty

    set to Long.

    In this application the arrival date is al$ays t$o days

    after drop2off or three days if a Sunday is reached.

    DateTimePickerorm!cs

    (1 of !

    33

  • 7/26/2019 c15.ppt

    33/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$116 'e"onstrating DateTimePicker. %Part 1 o$ *.(

    DateTimePickerorm!cs

    (* of !

    3*

    5

  • 7/26/2019 c15.ppt

    34/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    DateTimePickerorm!cs

    (- of !

    Fi$ 15$116 'e"onstrating DateTimePicker. %Part 2 o$ *.(

    :etrieving the selected date from

    the Valueproperty.

    'he DateTimestructure+s Day%'eekproperty determines the day of the $ee) on

    $hich the selected date falls.

    Using DateTime+s $ddDaysmethod toincrease the date by t$o days or three days.

    3+

    5 tli

  • 7/26/2019 c15.ppt

    35/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    DateTimePickerorm!cs

    ( of !

    Fi$ 15$116 'e"onstrating DateTimePicker. %Part 3 o$ *.(

    Setting the

    MinDateand

    MaxDateproperties to )eep

    drop2off sometime

    in the ne0t year.

    3

    5 tli

  • 7/26/2019 c15.ppt

    36/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    DateTimePickerorm!cs

    ( of !

    Fi$ 15$116 'e"onstrating DateTimePicker. %Part * o$ *.(

    a Clicking the do#n arro# b Selecting a day from the calendar

    c The %abel updates d Selecting another day

    3-

  • 7/26/2019 c15.ppt

    37/146

    2009 Pearson Education, Inc. All rights reserved.

    15$5 LinkLabelontrol 'he LinkLabelcontrol displays lin)s to other resources such as

    files or $eb pages (Fig. 1.1*!.

    Fi$ 15$123LinkLabelcontrol in running progra".

    4ooandFeel O6ser7ation 15$'ALinkLabelis the preerred control or indicatin' that theuser can click a link to -ump to a resource such as a +eb pa'e$

    thou'h other controls can perorm similar tasks.

    LinkLabelon a Formand image displays #hen

    mouse mo'es o'erLinkLabel

    3

  • 7/26/2019 c15.ppt

    38/146

    2009 Pearson Education, Inc. All rights reserved.

    15$5 LinkLabelontrol /ont$0

    Fi$ 15$1'3LinkLabelproperties and an event. %Part 1 o$ 2.(

  • 7/26/2019 c15.ppt

    39/146

    2009 Pearson Education, Inc. All rights reserved.

    15$5 LinkLabelontrol /ont$0

    Fi$ 15$1'3LinkLabelproperties and an event. %Part 2 o$ 2.(

    *0

    5utline

  • 7/26/2019 c15.ppt

    40/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    LinkLabelTestorm!cs

    (1 of 7 !

    3lass LinkLabelTestForm(Fig. 1.1! uses threeLinkLabels.

    "ethod Startof class Processallo$s you to e0ecute

    other programs or load documents or $eb sites from anapplication.

    Fi$ 15$1(6 LinkLabels used to lin) to a drive,a we# page and an application. %Part 1 o$ .(

    *1

    5utline

  • 7/26/2019 c15.ppt

    41/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1(6 LinkLabels used to lin) to a drive,a we# page and an application. %Part 2 o$ .(

    Setting the LinkVisite!property totrue changing the lin)+s color to

    purple.

    9pening a $eb

    page in the user+s

    default $eb

    bro$ser.

    LinkLabelTestorm!cs

    (* of 7 !

    9pening a WindowsE9plorer$indo$.

    (the #symbol indicates that characters inthe stringshould be interpretedliterally!.

    *2

    5utline

  • 7/26/2019 c15.ppt

    42/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1(6 LinkLabels used to lin) to a drive,a we# page and an application. %Part 3 o$ .(

    9pening an application.

  • 7/26/2019 c15.ppt

    43/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1(6 LinkLabels used to lin) to a drive,a we# page and an application. %Part * o$ .(

    Click rstLinkLabel

    tolook at contents ofC dri'e

    LinkLabelTestorm!cs

    ( of 7 !

    **

    5utline

  • 7/26/2019 c15.ppt

    44/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1(6 LinkLabels used to lin) to a drive,a we# page and an application. %Part + o$ .(

    Click secondLinkLabelto go toDeitel #ebsite

    LinkLabelTestorm!cs

    ( of 7 !

    *+

    5utline

  • 7/26/2019 c15.ppt

    45/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1(6 LinkLabels used to lin) to a drive,a we# page and an application. %Part o$ .(

    Click on thirdLinkLabelto open )otepad

    LinkLabelTestorm!cs

    (7 of 7 !

    *

  • 7/26/2019 c15.ppt

    46/146

    2009 Pearson Education, Inc. All rights reserved.

    15$) ListBoxontrol

    'he ListBoxcontrol allo$s the user to vie$ andselect from multiple items in a list.

    'he CheckedListBoxcontrol e0tends a ListBoxby including CeckBoxes ne0t to each item in the list.

    Figure 1.1 displays a ListBoxand aCecke!ListBox.

    *-

  • 7/26/2019 c15.ppt

    47/146

    2009 Pearson Education, Inc. All rights reserved.

    15$) ListBoxontrol /ont$0

    Fi$ 15$153ListBoxand Cecke!ListBoxon a Form.

    ListBox

    Selecteditems

    Checked item

    Scrollbars

    appear ifnecessary

    Cecke!ListBox

    *

  • 7/26/2019 c15.ppt

    48/146

    2009 Pearson Education, Inc. All rights reserved.

    15$) ListBoxontrol /ont$0

    Fi$ 15$1)3ListBoxproperties, "ethods and an event. %Part 1 o$ 2.(

    *9

  • 7/26/2019 c15.ppt

    49/146

    2009 Pearson Education, Inc. All rights reserved.

    15$) ListBoxontrol /ont$0

    Fi$ 15$1)3ListBoxproperties, "ethods and an event.%Part 2 o$ 2.(

    +0

  • 7/26/2019 c15.ppt

    50/146

    2009 Pearson Education, Inc. All rights reserved.

    15$) ListBoxontrol /ont$0 'o add items to a ListBoxor to a Cecke!ListBox $e must

    add ob=ects to its Itemscollection.myListBox$Items$%!! myListItem'(

    /ou can add items to ListBoxes and Cecke!ListBoxesvisually by e0amining the Itemsproperty in the Properties$indo$ (Fig. 1.15!.

    Fi$ 15$1*3#trin ollection Editor.

    +1

    5utline

  • 7/26/2019 c15.ppt

    51/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    ListBoxTestorm!cs

    (1 of !

    Figure 1.18 uses class ListBoxTestFormto addremove and clear items from ListBox!ispla)ListBox.>

    Fi$ 15$1+6 Progra" that adds, re"oves and clears ListBoxite"s. %Part 1 o$ +.(

    +2

    5utline

  • 7/26/2019 c15.ppt

    52/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1+6 Progra" that adds, re"oves and clears ListBoxite"s. %Part 2 o$ +.(

    ,dding strings usingmethod $ddof the Itemscollection.

    Using method

    (emo)e$tto removethe item at the selected

    inde0.

    ListBoxTestorm!cs

    (* of !

    +3

    5utline

  • 7/26/2019 c15.ppt

    53/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1+6 Progra" that adds, re"oves and clears ListBoxite"s. %Part 3 o$ +.(

    Using method Clearof the Itemscollectionto remove all the

    entries.

    ListBoxTestorm!cs

    (- of !

    +*

    5utline

  • 7/26/2019 c15.ppt

    54/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1+6 Progra" that adds, re"oves and clears ListBoxite"s. %Part * o$ +.(

    a !dding an item b !dding more items

    ListBoxTestorm!cs

    ( of !

    ++

    5utline

  • 7/26/2019 c15.ppt

    55/146

    2009 Pearson Education,Inc. All rights reserved.

    5utline

    Fi$ 15$1+6 Progra" that adds, re"oves and clears ListBoxite"s. %Part + o$ +.(

    c !n item has been remo'ed d Clearing the list

    ListBoxTestorm!cs

    ( of !

    +

  • 7/26/2019 c15.ppt

    56/146

    2009 Pearson Education, Inc. All rights reserved.

    15$* CheckedListBoxontrol

    Fi$ 15$1,3Cecke!ListBoxproperties, "ethods and events. %Part 1 o$ 2.(

    'he Cecke!ListBoxcontrol derives fromListBox

    and displays a CeckBox$ith each item (Fig. 1.1;!.

    +-

  • 7/26/2019 c15.ppt

    57/146

    2009 Pearson Education, Inc. All rights reserved.

    Fi$ 15$1,3Cecke!ListBoxproperties, "ethods and events. %Part 2 o$ 2.(

    15$* CheckedListBoxontrol /ont$0

    +

  • 7/26/2019 c15.ppt

    58/146

    2009 Pearson Education, Inc. All rights reserved.

    15$* CheckedListBoxontrol

    ommon Prorammin Error 15$1#he %/ displays an error messa'e i you attempt to set

    the SelectionModeproperty to MultiSimpleor

    Multi#xtendedin the Properties+indo+ o a

    CheckedListBox. % this value is set pro'rammatically$

    a runtime error occurs.

    +9

    5utline

  • 7/26/2019 c15.ppt

    59/146

    2009 Pearson Education,Inc. All rights reserved.

    CheckedListBoxTestorm!cs

    (1 of !

    3lass Cecke!ListBoxTestFormuses a

    Cecke!ListBoxand a ListBoxto display a user+s

    selection of boo)s (Fig. 1.*4!.

    Fi$ 15$2-6 Cecke!ListBoxand ListBoxused in a progra" todisplay a user selection. %Part 1 o$ *.(

    0

    5utline

  • 7/26/2019 c15.ppt

    60/146

    2009 Pearson Education,Inc. All rights reserved.

    CheckedListBoxTestorm!cs

    (* of !

    Fi$ 15$2-6 Cecke!ListBoxand ListBoxused in a progra" todisplay a user selection. %Part 2 o$ *.(

    'his event handler

    maintains a list ofchec)ed items in the

    ListBox.

    ?etermining $hether

    the user chec)ed or

    unchec)ed the item.

    1

    5utline

  • 7/26/2019 c15.ppt

    61/146

    2009 Pearson Education,Inc. All rights reserved.

    CheckedListBoxTestorm!cs

    (- of !

    a !pplication at start b Selecting and checking items

    Fi$ 15$2-6 Cecke!ListBoxand ListBoxused in a progra" to

    display a user selection. %Part 3 o$ *.(

    2

    5utline

  • 7/26/2019 c15.ppt

    62/146

    2009 Pearson Education,Inc. All rights reserved.

    CheckedListBoxTestorm!cs

    ( of !

    c *nchecking selected items d Checking items

    Fi$ 15$2-6 Cecke!ListBoxand ListBoxused in a progra" to

    display a user selection. %Part * o$ *.(

    3

    1 + C b B l

  • 7/26/2019 c15.ppt

    63/146

    2009 Pearson Education, Inc. All rights reserved.

    15$+ ComboBoxontrol

    'he ComboBoxcontrol combines TextBoxfeatures $ith adrop0do+n list.

    Figure 1.*1 sho$s a sample ComboBoxin three different states.

    Fi$ 15$213ComboBoxde"onstration.

    Click the do#n arro#

    to display items in drop+do#n

    list

    Selecting an item from drop+do#n

    list changes tet in TextBoxportion

    *

    C b

  • 7/26/2019 c15.ppt

    64/146

    2009 Pearson Education, Inc. All rights reserved.

    15$+ ComboBoxontrol /ont$0

    Fi$ 15$223ComboBoxproperties and an event.

    +

    15 + C b B t l / t 0

  • 7/26/2019 c15.ppt

    65/146

    2009 Pearson Education, Inc. All rights reserved.

    15$+ ComboBoxontrol /ont$0

    4ooandFeel O6ser7ation 15$(1se a ComboBoxto save space on a 21%. A disadvanta'eis that$ unlike +ith a ListBox$ the user cannot seeavailable items +ithout e"pandin' the drop0do+n list.

    4ooandFeel O6ser7ation 15$5

    Make lists &such as ComboBoxes( editable only i the

    pro'ram is desi'ned to accept user0submitted elements.

    5utline

  • 7/26/2019 c15.ppt

    66/146

    2009 Pearson Education,Inc. All rights reserved.

    ComboBoxTestorm!cs

    ( 1 of !

    3lass ComboBoxTestForm(Fig. 1.*-! allo$s users toselect a shape to dra$ by using a ComboBox.

    Set the ComboBox+s DropDownSt)leto DropDownList

    to restrict users to preset options.

    Fi$ 15$2'6 ComboBoxused to draw a selected shape. %Part 1 o$ +.(

    -

    5utline

  • 7/26/2019 c15.ppt

    67/146

    2009 Pearson Education,Inc. All rights reserved.

    ComboBoxTestorm!cs

    ( * of !

    'he *rapicsob=ect allo$sa pen or brush to dra$ on a

    component

    'he Penob=ect is used to dra$the outlines of shapes.

    'he Soli!Brusob=ect isused to fill solid shapes.

    Fi$ 15$2'6 ComboBoxused to draw a selected shape. %Part 2 o$ +.(

    5utline

  • 7/26/2019 c15.ppt

    68/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ComboBoxTestorm!cs

    ( - of !

    Selecte!In!exdetermines $hich item the

    user selected.

    Draw#llipseta)es a Pen

    the coordinates of the centerand the dimensions of the

    ellipse.

    Fi$ 15$2'6 ComboBoxused to draw a selected shape. %Part 3 o$ +.(

    Draw(ectan*leta)es aPen+the coordinates of theupper2left corner and the

    dimensions of the rectangle.

    DrawPieta)es a Pen thecoordinates of the upper2left

    corner its $idth and height

    the start angle and the s$eep

    angle of the pie.

    9

    5utline

  • 7/26/2019 c15.ppt

    69/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ComboBoxTestorm!cs

    ( of !

    Fi$ 15$2'6 ComboBoxused to draw a selected shape. %Part * o$ +.(

    -0

    5utlinea b

  • 7/26/2019 c15.ppt

    70/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ComboBoxTestorm!cs

    ( of !

    Fi$ 15$2'6 ComboBoxused to draw a selected shape. %Part + o$ +.(

    c d

    -1

    15 , TreeView ontrol

  • 7/26/2019 c15.ppt

    71/146

    2009 Pearson Education, Inc. All rights reserved.

    15$, TreeViewontrol

    'he

    TreeViewcontrol displays nodeshierarchicallyin a tree.

    , parent nodecontains child nodes and the child

    nodes can be parents to other nodes.

    '$o child nodes that have the same parent node are

    considered siblin' nodes.

    'he first parent node of a tree is the rootnode

    (a TreeViewcan have multiple roots!.

    -2

    15 , TreeView ontrol /ont 0

  • 7/26/2019 c15.ppt

    72/146

    2009 Pearson Education, Inc. All rights reserved.

    15$, TreeViewontrol /ont$0

    'he nodes in a TreeView(Fig. 1.*! are instances of classTree+ode.

    6ach Tree,o!ehas a +odescollection(type Tree+odeCollection! $hich contains a list of its children.

    Fi$ 15$2(3TreeViewdisplaying a sa"ple tree.

    $oot node

    Click - to epandnode and display

    child nodes

    Click. to collapsenode and hidechild nodes

    Child nodes (ofManager/

    -3

    15 , T Vi t l / t 0

  • 7/26/2019 c15.ppt

    73/146

    2009 Pearson Education, Inc. All rights reserved.

    15$, TreeViewontrol /ont$0

    Fi$ 15$253 TreeViewproperties and an event.

    -*

    15 , T Vi t l / t 0

  • 7/26/2019 c15.ppt

    74/146

    2009 Pearson Education, Inc. All rights reserved.

    15$, TreeViewontrol /ont$0

    Fi$ 15$2)3 Tree,o!eproperties and "ethods. %Part 1 o$ 2.(

    -+

    15 , T Vi t l / t 0

  • 7/26/2019 c15.ppt

    75/146

    2009 Pearson Education, Inc. All rights reserved.

    15$, TreeViewontrol /ont$0

    Fi$ 15$2)3 Tree,o!eproperties and "ethods. %Part 2 o$ 2(

    -

    15 , TreeView ontrol /ont 0

  • 7/26/2019 c15.ppt

    76/146

    2009 Pearson Education, Inc. All rights reserved.

    15$, TreeViewontrol /ont$0

    'o add nodes to the TreeViewvisually clic) the ellipsis ne0tto the ,o!esproperty in the Properties$indo$.

    'his opens the TreeNodeEditor(Fig.1.*5!.

    Fi$ 15$2*3TreeNode Editor.

    Delete current node

    --

    15 , TreeView ontrol /ont 0

  • 7/26/2019 c15.ppt

    77/146

    2009 Pearson Education, Inc. All rights reserved.

    15$, TreeViewontrol /ont$0

    'o add nodes programmatically first create a root node.

    myTreeView$,o!es$%!! newTree,o!e rootLabel ' '(

    'o add children to a root node first select the appropriate

    root node@

    myTreeView$,o!es myInex. 'o add a child to the root node at inde0 myInex $rite@

    myTreeView$,o!es myInex .$,o!es$%!!newTree,o!eChilLabel' '(

    -

    5utline

    l T Vi Di t St t F

  • 7/26/2019 c15.ppt

    78/146

    2009 Pearson Education,

    Inc. All rights reserved.

    TreeViewDirectoryStructureorm

    !Cs

    ( 1 of 7 !

    3lass TreeViewDirector)StructureForm(Fig. 1.*8! uses aTreeViewto display the contents of adirectory.

    Fi$ 15$2+6 TreeViewused to display directories. %Part 1 o$ .(

    -9

    5utline

  • 7/26/2019 c15.ppt

    79/146

    2009 Pearson Education,

    Inc. All rights reserved.

    TreeViewDirectoryStructureorm

    !Cs

    ( * of 7 !

    Fi$ 15$2+6 TreeViewused to display directories. %Part 2 o$ .(

    "ethod ,etDirectoriesta)es the given directory and

    returns an array of strings(the subdirectories!.

    0

    5utline

  • 7/26/2019 c15.ppt

    80/146

    2009 Pearson Education,

    Inc. All rights reserved.

    TreeViewDirectoryStructureorm

    !Cs

    ( - of 7 !

    Fi$ 15$2+6 TreeViewused to display directories. %Part 3 o$ .(

    'he full path name is

    reduced to =ust the

    directory name.

    6ach subdirectory+s

    name is created as a

    node.

    Using method %!!toadd the subdirectories

    as child nodes.3alling PopulateTreeViewrecursively on everysubdirectory populates the TreeView$ith theentire directory structure.

    1

    5utline

  • 7/26/2019 c15.ppt

    81/146

    2009 Pearson Education,

    Inc. All rights reserved.

    TreeViewDirectoryStructureorm

    !Cs

    ( of 7 !

    Fi$ 15$2+6 TreeViewused to display directories. %Part * o$ .(

  • 7/26/2019 c15.ppt

    82/146

    2009 Pearson Education,

    Inc. All rights reserved.

    TreeViewDirectoryStructureorm

    !Cs

    ( of 7 !

    Fi$ 15$2+6 TreeViewused to display directories. %Part + o$ .(

    35utline

  • 7/26/2019 c15.ppt

    83/146

    2009 Pearson Education,

    Inc. All rights reserved.

    TreeViewDirectoryStructureorm

    !Cs

    ( 7 of 7 !

    Fi$ 15$2+6 TreeViewused to display directories. %Part o$ .(

    a b

    *

    15 1- ListView ontrol /ont 0

  • 7/26/2019 c15.ppt

    84/146

    2009 Pearson Education, Inc. All rights reserved.

    'he ListViewcontrol is more versatile than aListBoxand can display items in different formats.

    For e0ample a ListViewcan display icons ne0t tothe list items and sho$ the details of items in columns.

    15$1- ListViewontrol /ont$0

    +

    15 1- ListView ontrol /ont 0

  • 7/26/2019 c15.ppt

    85/146

    2009 Pearson Education, Inc. All rights reserved.

    15$1- ListViewontrol /ont$0

    Fi$ 15$2,3 ListViewproperties and an event.

    15$1- ListView ontrol /ont$0

  • 7/26/2019 c15.ppt

    86/146

    2009 Pearson Education, Inc. All rights reserved.

    15$1- ListViewontrol /ont$0

    ListViewallo$s you to define the images used asicons for items.

    3reate a ListView then select the -ma*espropertyin the Properties$indo$ to display the Image

    CollectionEditor(Fig. 1.-4!. ,dding images this $ay embeds them into the

    application.

    -

    15$1- ListView ontrol /ont$0

  • 7/26/2019 c15.ppt

    87/146

    2009 Pearson Education, Inc. All rights reserved.

    15$1- ListViewontrol /ont$0

    Fi$ 15$'-3ImageCollectionEditorwindow $or anImageListco"ponent.

    15$1- ListView ontrol /ont$0

  • 7/26/2019 c15.ppt

    88/146

    2009 Pearson Education, Inc. All rights reserved.

    15$1- ListViewontrol /ont$0

    Set property SmallImageListof the ListViewto thene$ ImageListob=ect.

    Aroperty Small-ma*eListspecifies the image list forthe small icons.

    Aroperty Lar*e-ma*eListsets the ImageListforlarge icons.

    95utline

    3lass ListViewTestForm (Fig 1 -1! displays files and

  • 7/26/2019 c15.ppt

    89/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ListViewTestorm!cs

    ( 1 of 8 !

    3lass ListViewTestForm(Fig. 1.-1! displays files andfolders in a ListView.

    If a file or folder is inaccessible because of permission

    settings a MessageBoxappears.

    Fi$ 15$'16 ListViewdisplaying $iles and $olders. %Part 1 o$ .(

    905utline

  • 7/26/2019 c15.ppt

    90/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ListViewTestorm!cs

    ( * of 8 !

    Fi$ 15$'16 ListViewdisplaying $iles and $olders. %Part 2 o$ .(

    3hec)ing $hether anything is

    selected inbrowserListView.

    ?etermining $hether the user

    chose the first item (Go %p

    one le7el!.

    915utline

  • 7/26/2019 c15.ppt

    91/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ListViewTestorm!cs

    ( - of 8 !

    Fi$ 15$'16 ListViewdisplaying $iles and $olders. %Part 3 o$ .(

    Using property Parenttoreturn the parent directory.

    925utline

  • 7/26/2019 c15.ppt

    92/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ListViewTestorm!cs

    ( of 8 !

    Fi$ 15$'16 ListViewdisplaying $iles and $olders. %Part * o$ .(

    935utline

  • 7/26/2019 c15.ppt

    93/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ListViewTestorm!cs

    ( of 8 !

    Fi$ 15$'16 ListViewdisplaying $iles and $olders. %Part + o$ .(

    "ethod ,etilesreturns an

    array of class ile-noob=ects.

    Iterating through

    subdirectories and adding

    them to

    browserListView.

    Iterating through subdirectories and

    adding them to

    browserListView.

    "ethod ,etDirectoriesreturns an array of

    Director)In/oob=ectsrepresenting the subdirectories.

    9*5utline

  • 7/26/2019 c15.ppt

    94/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ListViewTestorm!cs

    ( 7 of 8 !

    Fi$ 15$'16 ListViewdisplaying $iles and $olders. %Part o$ .(

    Iterating through

    subdirectories and

    adding them to

    browserListView.

    9+5utline

  • 7/26/2019 c15.ppt

    95/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ListViewTestorm!cs

    ( 5 of 8 !

    Fi$ 15$'16 ListViewdisplaying $iles and $olders. %Part - o$ .(

    Folder and file icon images are

    added to the Imagescollection of/ileFol!erImageList.

    'he application loads its home

    directory into the ListView$henit first loads.

    95utline

    a

  • 7/26/2019 c15.ppt

    96/146

    2009 Pearson Education,

    Inc. All rights reserved.

    ListViewTestorm!cs

    ( 8 of 8 !

    Fi$ 15$'16 ListViewdisplaying $iles and $olders. %Part o$ .(

    c

    b

    9-

    15$1- ListViewontrol /ont$0

  • 7/26/2019 c15.ppt

    97/146

    2009 Pearson Education, Inc. All rights reserved.

    / 0

    'his program loads Buic)ly because it inde0es only the

    files in the current directory.

    ,s a result a small delay may occur $hen a ne$ directory

    is loaded.

    #oftware Enineerin O6ser7ation 15$2

    When desi'nin' applications that run or lon' periods o

    time$ you mi'ht choose a lar'e initial delay. 3o+ever$ in

    applications that run or only short periods$ developersoten preer ast initial loadin' times and small delays

    ater each action.

    9

    15$11 TabControlontrol

  • 7/26/2019 c15.ppt

    98/146

    2009 Pearson Education, Inc. All rights reserved.

    'he TabControlcreates tabbed $indo$s such as those$e have seen in Visual Studio (Fig. 1.-*!

    Fi$ 15$'23!a##ed windows in isual /tudio.

    Tabs

    99

    15$11 TabControlontrol /ont$0

  • 7/26/2019 c15.ppt

    99/146

    2009 Pearson Education, Inc. All rights reserved.

    / 0

    TabControls contain TabPa*eob=ects $hich aresimilar to Panels.

    First add controls to the TabPageob=ects then add theTabPages to the TabControl.

    myTab!a"e$Controls$%!! myControl'(myTabControl$TabPages$%!! myTab!a"e'(

  • 7/26/2019 c15.ppt

    100/146

    2009 Pearson Education, Inc. All rights reserved.

    / 0

    Fi$ 15$''3TabControlwithTabPagese7a"ple.

    TabPage

    Controls inTabPage

    TabControl

    101

    15$11 TabControlontrol /ont$0

  • 7/26/2019 c15.ppt

    101/146

    2009 Pearson Education, Inc. All rights reserved.

    / 0

    ,dd TabControlsvisually by dragging anddropping them onto a Formin esignmode.

    'o add TabPages in esignmode right clic) theTabControland select Add Tab(Fig. 1.-!.

    'o select a TabPage clic) the control areaunderneath the tabs.

    102

    15$11 TabControlontrol /ont$0

  • 7/26/2019 c15.ppt

    102/146

    2009 Pearson Education, Inc. All rights reserved.

    / 0

    Fi$ 15$'(3TabPages added to a TabControl.

    103

    15$11 TabControlontrol /ont$0

  • 7/26/2019 c15.ppt

    103/146

    2009 Pearson Education, Inc. All rights reserved.

    / 0

    Fi$ 15$'53 TabControlproperties and an event.

    10*5utline

    3lass 1singTabsForm(Fig. 1.-7! uses a TabControl

  • 7/26/2019 c15.ppt

    104/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*Tabsorm!cs

    ( 1 of 7 !

    g ( g !to display various options relating to the te0t on a label

    (Color Si!eand "essage!.

    Fi$ 15$')6 TabControlused to display various $ont settings. %Part 1 o$ .(

    10+5utline

  • 7/26/2019 c15.ppt

    105/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*Tabsorm!cs

    ( * of 7 !

    Fi$ 15$')6 TabControlused to display various $ont settings. %Part 2 o$ .(

    105utline

  • 7/26/2019 c15.ppt

    106/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*Tabsorm!cs

    ( - of 7 !

    Fi$ 15$')6 TabControlused to display various $ont settings. %Part 3 o$ .(

    10-5utline

  • 7/26/2019 c15.ppt

    107/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*Tabsorm!cs

    ( of 7 !

    Fi$ 15$')6 TabControlused to display various $ont settings. %Part * o$ .(

    105utline

  • 7/26/2019 c15.ppt

    108/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*Tabsorm!cs

    ( of 7 !

    Fi$ 15$')6 TabControlused to display various $ont settings. %Part + o$ .(

    a Color tab b Si0e tab

    1095utline

  • 7/26/2019 c15.ppt

    109/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*Tabsorm!cs

    ( 7 of 7 !c Message tab d !bout tab

    Fi$ 15$')6 TabControlused to display various $ont settings. %Part o$ .(

    110

    15$11 TabControlontrol /ont$0

  • 7/26/2019 c15.ppt

    110/146

    2009 Pearson Education, Inc. All rights reserved.

    #oftware Enineerin O6ser7ation 15$'

    A TabPa*ecan act as a container or a sin'le lo'ical'roup o (adioButtons$ enorcin' their mutuale"clusivity.

    111

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows

  • 7/26/2019 c15.ppt

    111/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows

    "any comple0 applications are multiple document

    interace &M%(programs $hich allo$ users to edit

    multiple documents at once.

    ,n "?I program+s main $indo$ is called the parent

    +indo+ and each $indo$ inside the application isreferred to as a child +indo+.

    Figure 1.-5 depicts a sample "?I application $ith

    t$o child $indo$s.

    112

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont 0

  • 7/26/2019 c15.ppt

    112/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    MD1 parent

    MD1 child

    MD1 child

    Fi$ 15$'*3&'I parent window and &'I child windows.

    113

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont 0

  • 7/26/2019 c15.ppt

    113/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    Single Document 1nterface (SD1

    Fi$ 15$'+3/'I and &'I $or"s.

    Multiple Document 1nterface (MD1

    'o create an "?I Form create a ne$ Formand set its

    -sMdiContainerproperty to true(Fig. 1.-8!.

    11*

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont 0

  • 7/26/2019 c15.ppt

    114/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    :ight clic) the pro=ect in the Sol#tionExplorer

    select Pro$ect%Add &indo's Form( andname the file.

    Set the Form+s MdiParentproperty to the parent Formand call the child Form+s Sowmethod.

    ChilFormClass #hilForm=New ChilFormClass'(

    #hilForm.M!iParent = $arentForm%

    #hilForm.Sow'(

    In most cases the parent Formcreates the child so the$arentFormreference is tis.

    11+

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont 0

  • 7/26/2019 c15.ppt

    115/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    Fi$ 15$',3 &'I parent and &'I child properties, "ethod and event.

    11

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont$0

  • 7/26/2019 c15.ppt

    116/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    Figure 1.4 sho$s t$o images@ one containing t$o minimi#ed child

    $indo$s and a second containing a ma0imi#ed child $indo$.

    Parent+#indo# iconsminimi0e, maimi0e and close

    Maimi0ed child #indo# iconsminimi0e, restore and close

    Minimi0ed child #indo# iconsrestore, maimi0e and close

    Parent title bar indicatesmaimi0ed child

    Fi$ 15$(-3&ini"i8ed and "a7i"i8ed child windows.

    11-

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont$0

  • 7/26/2019 c15.ppt

    117/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    Aroperty Mdi'indowList-temof classMenuStripspecifies $hich menu if any displays alist of open child $indo$s.

  • 7/26/2019 c15.ppt

    118/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    )ine or more child#indo#s enables the

    More 2indo#s3 option

    Fi$ 15$(13MenuItemproperty M!iListe7a"ple.

    Child #indo#s list

    119

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont$0

  • 7/26/2019 c15.ppt

    119/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    Good Prorammin Practice 15$1

    When creatin' M% applications$ include a menu that

    displays a list o the open child +indo+s. #his helps the

    user select a child +indo+ )uickly$ rather than havin' to

    search or it in the parent +indo+.

    120

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont$0

  • 7/26/2019 c15.ppt

    120/146

    2009 Pearson Education, Inc. All rights reserved.

    Windows /ont$0

    "?I containers allo$ you to organi#e the placement of

    its child $indo$s.

    "ethod LayoutMdita)es a value of theMdiLayoutenumeration (Fig. 1.*!.

    121

    15$12 &%ltiple .oc%ment Interface /&.I0

    Windows /ont$0

  • 7/26/2019 c15.ppt

    121/146

    2009 Pearson Education, Inc. All rights reserved.

    do s /o t 0a%rrangeIcons

    Fi$ 15$(23M!iLa)outenu"eration values.

    bCasca!e

    cTile2ori3ontal dTileVertical

    122

    5utline

    3lass 1singMDIForm(Fig. 1.-! demonstrates "?I$indo$s

  • 7/26/2019 c15.ppt

    122/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*MD-orm!cs

    ( 1 of 7 !

    $indo$s.

    Fi$ 15$('6 &'I parent4window class. %Part 1 o$ .(

    123

    5utline

  • 7/26/2019 c15.ppt

    123/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*MD-orm!cs

    ( * of 7 !

    Fi$ 15$('6 &'I parent4window class. %Part 2 o$ .(

    ,dding a ne$ child Form$ith certain properties.

    ,dding a ne$ child Form$ith certain properties.

    12*

    5utline

  • 7/26/2019 c15.ppt

    124/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*MD-orm!cs

    ( - of 7 !

    Fi$ 15$('6 &'I parent4window class. %Part 3 o$ .(

    ,dding a ne$ child Form$ith certain properties.

    12+

    5utline

  • 7/26/2019 c15.ppt

    125/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*MD-orm!cs

    ( of 7 !

    Fi$ 15$('6 &'I parent4window class. %Part * o$ .(

    Setting the layout of child

    Forms.

    Setting the layout of child

    Forms.

    Setting the layout of child

    Forms.

    12

    5utline

  • 7/26/2019 c15.ppt

    126/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*MD-orm!cs

    ( of 7 !

    Fi$ 15$('6 &'I parent4window class. %Part + o$ .(

    a Creating a child #indo# b 4ie#ing the child #indo#

    12-

    5utline

  • 7/26/2019 c15.ppt

    127/146

    2009 Pearson Education,

    Inc. All rights reserved.

    .sin*MD-orm!cs

    ( 7 of 7 !

    Fi$ 15$('6 &'I parent4window class. %Part o$ .(

    Changing child #indo# organi0ation d Child #indo#s in Cascade 'ie#

    12

    5utline

    ?efine the "?I child class by right clic)ing the pro=ect in the

    Sol#tion Explorer and selecting Add &indo's

  • 7/26/2019 c15.ppt

    128/146

    2009 Pearson Education,

    Inc. All rights reserved.

    Childorm!cs

    ( 1 of * !

    Sol#tionExplorerand selecting Add &indo'sForm(.

    Came the ne$ class Cil!Form(Fig. 1.!.

    Fi$ 15$((6&'I child Cil!Form. %Part 1 o$ 2.(

    129

    5utline

  • 7/26/2019 c15.ppt

    129/146

    2009 Pearson Education,

    Inc. All rights reserved.

    Childorm!cs

    ( * of * !

    Fi$ 15$((6&'I child Cil!Form. %Part 2 o$ 2.(

    Setting the title2bar te0t.

    :etrieving the

    specified image

    resource and

    displaying it.

    130

    15$1' "is%al Inheritance

  • 7/26/2019 c15.ppt

    130/146

    2009 Pearson Education, Inc. All rights reserved.

    4isual inheritanceenables you to achieve visual

    consistency.

    For e0ample you could define a base Formthatcontains a product+s logo and a specific bac)ground

    color. /ou then could use the base Formthroughout an

    application for uniformity and branding.

    131

    5utline 3lass VisualIneritanceBaseForm(Fig. 1.!derives fromForm.

    :ight clic) the pro=ect name in the Sol#tion Explorer

  • 7/26/2019 c15.ppt

    131/146

    2009 Pearson Education,

    Inc. All rights reserved.

    Visual-nheritanceBaseorm!cs

    ( 1 of * !

    :ight clic) the pro=ect name in theSol#tionExplorerand selectProperties, then choose theApplication

    tab. In the)#tp#ttypedrop2do$n list change&indo's

    ApplicationtoClass*ibrary.

    uilding the pro=ect produces the$!ll.

    Fi$ 15$(56lass VisualIneritanceBaseForm, which inherits $ro"class Form, contains a Button%*earn"ore(. %Part 1 o$ 2.(

    132

    5utline

  • 7/26/2019 c15.ppt

    132/146

    2009 Pearson Education,

    Inc. All rights reserved.

    Visual-nheritanceBaseorm!cs

    ( * of * !

    Fi$ 15$(56lass VisualIneritanceBaseForm, which inherits $ro"class Form, contains a Button%*earn"ore(. %Part 2 o$ 2.(

    133

    15$1' "is%al Inheritance /ont$0

  • 7/26/2019 c15.ppt

    133/146

    2009 Pearson Education, Inc. All rights reserved.

    'o visually inherit from

    VisualIneritanceBaseForm create a ne$

  • 7/26/2019 c15.ppt

    134/146

    2009 Pearson Education, Inc. All rights reserved.

    In esignvie$ the ne$ application+s Formshould no$ display the

    controls inherited from the base Form(Fig. 1.7!.

    Fi$ 15$()3Formde"onstrating visual inheritance.

    13+

    5utline

    3lass VisualIneritanceTestForm(Fig. 1.5! is aderived class of VisualIneritanceBaseForm.

  • 7/26/2019 c15.ppt

    135/146

    2009 Pearson Education,

    Inc. All rights reserved.

    Visual-nheritanceTestorm!cs

    ( 1 of * !

    Fi$ 15$(*6lass VisualIneritanceTestForm, which inherits$ro" class VisualIneritanceBaseForm, contains an

    additional Button. %Part 1 o$ 2.(

    Inheriting the

    Form+s propertiesand appearance.

    13

    5utline

  • 7/26/2019 c15.ppt

    136/146

    2009 Pearson Education,

    Inc. All rights reserved.

    Visual-nheritanceTestorm!cs

    ( * of * !

    Deri'ed class

    cannot modifythese controls5

    Deri'ed class can

    modify thiscontrol5

    Fi$ 15$(*6lass VisualIneritanceTestForm, which inherits$ro" class VisualIneritanceBaseForm, contains an

    additional Button. %Part 2 o$ 2.(

    13-

    15$1( User.efined ontrols

  • 7/26/2019 c15.ppt

    137/146

    2009 Pearson Education, Inc. All rights reserved.

    'he .C6' Frame$or) allo$s you to create custom

    controls.

    3ustom controls appear in the user+s Toolbox.

    'here are multiple $ays to create a custom control

    depending on the level of customi#ation that you $ant.

    13

    15$1( User.efined ontrols /ont$0

  • 7/26/2019 c15.ppt

    138/146

    2009 Pearson Education, Inc. All rights reserved.

    Fi$ 15$(+3 usto"4control creation.

    139

    15$1( User.efined ontrols /ont$0

  • 7/26/2019 c15.ppt

    139/146

    2009 Pearson Education, Inc. All rights reserved.

    Timersare invisible components that generate Tick

    events at a set interval.

    'he Timer+s %ntervalproperty defines the number ofmilliseconds bet$een events.

    1*0

    5utline

    3reate a1serControlclass for the pro=ect by selectingPro$ect % Add +ser Control (.

  • 7/26/2019 c15.ppt

    140/146

    2009 Pearson Education,

    Inc. All rights reserved.

    Clock.serControl!cs

    ( 1 of * !

  • 7/26/2019 c15.ppt

    141/146

    2009 Pearson Education,

    Inc. All rights reserved.

    Clock.serControl!cs

    ( * of * !

    Fi$ 15$(,61serControl4de$ined cloc). %Part 2 o$ 2.(

    DateTime!+owis thecurrent time.

    "ethod

    ToLon*TimeStrin*

    converts ,owto a

    string.

    1*2

    15$1( User.efined ontrols /ont$0

  • 7/26/2019 c15.ppt

    142/146

    2009 Pearson Education, Inc. All rights reserved.

    'o create a 1serControlthat can be re2used by others@

    3reate a ne$ Class *ibrarypro=ect.

    ?elete Class6$cs initially provided $ith the application.

    :ight clic) the pro=ect in the Sol#tionExplorerand selectAdd%+serControl(

    ,dd controls and functionality to the 1serControl(Fig. 1.4!.

    uild the pro=ect. Visual Studio creates a $!llfile for the1serControlin the output directory (bin70elease!.

    1*3

    15$1( User.efined ontrols /ont$0

  • 7/26/2019 c15.ppt

    143/146

    2009 Pearson Education, Inc. All rights reserved.

    Fi$ 15$5-3usto"4control creation.

    1**

    15$1( User.efined ontrols /ont$0

  • 7/26/2019 c15.ppt

    144/146

    2009 Pearson Education, Inc. All rights reserved.

    3reate a ne$

  • 7/26/2019 c15.ppt

    145/146

    2009 Pearson Education, Inc. All rights reserved.

    'he item $ill then appear in the C,ooseToolboxItemsdialog

    (Fig. 1.1!. 3hec) this item and clic) )-to add the item to the Toolbox.

    Fi$ 15$513usto" control added to the ToolBox.

    1*

    15$1( User.efined ontrols /ont$0

  • 7/26/2019 c15.ppt

    146/146

    'his control can no$ be added to the Form as if it $ere any other

    control (Fig. 1.*!.

    Fi 15 52 3 sto" control added to a Form

    )e#ly insertedcontrol)e# Tool"oicon