© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline 13.1 Introduction 13.2 Menus 13.3 LinkLabels 13.4 ListBoxes and CheckedListBoxes ListBoxes CheckedListBoxes 13.5 ComboBoxes 13.6 TreeViews 13.7 ListViews 13.8 Tab Control 13.9 Multiple-Document-Interface (MDI) Windows Visual Inheritance User-Defined Controls
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Continues study of Graphical User Interface Explores: –Menus –LinkLabels –ListBox –CheckedListBox –ComboBoxes –TreeView control –Tab controls –Multiple-document interface windows
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Menus Group related commands together Contain: –Commands –Submenus Exit uses Application class to quit Color options mutually exclusive Every option has its own event handler Font style options use XOR operator
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Menus Shortcut key Disabled command Separator bar Menu submenu Checked menu item Fig. 13.1Expanded and checked menus.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Menus Text boxes used to add items to menu MainMenu icon Menu Designer Place & character before the letter to be underlined Fig. 13.2Visual Studio.NET Menu Designer.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Menus Fig. 13.3MainMenu and MenuItem properties and events. (1 of 2)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Menus
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 4 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 5 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 6 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 7 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 8 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 9 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 10 of 10
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.3 LinkLabels Displays links to other objects –Uses event handlers to link to right file or program –Start method of Process class opens other programs Derived from class Label, inherits functionality
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved LinkLabels LinkLabel on a form Hand image displayed when mouse moves over LinkLabel Fig. 13.6LinkLabel control in running program.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved LinkLabels
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 4 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 5 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.4 ListBox es and CheckedList Boxes ListBoxe s –Allow users to view and select from items on a list –Static objects –SelectionMode property determines number of items that can be selected –Property Items returns all objects in list –Property SelectedItem returns current selected item –Property SelectedIndex returns index of selected item –Property GetSelected returns true if property at given index is selected –Use Add method to add to Items collection myListBox-> Items->Add ( “myListItem” )
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ListBox es and CheckedList Boxes CheckedListBoxe s –Extends ListBox by placing check boxes next to items –Can select more than one object at one time
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ListBox es and CheckedList Boxes Scroll bars appear if necessary Checked item Selected item ListBox CheckedListBox Fig ListBox and CheckedListBox on a form.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ListBox es and CheckedList Boxes
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ListBox es and CheckedList Boxes Fig String Collection Editor.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ListBox es Class ListBoxTest –Allows users to add and remove items from ListBox –Uses event handlers to add to, remove from and clear list
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 4
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 4
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 4
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 4 of 4
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
CheckedListBox es CheckedListBox derives from class ListBox –Can add to, remove from or clear list –Can select multiple items from the list –Properties CurrentValue and NewValue return state of object selected –Properties CheckedItems and CheckedIndices return the objects and indices of selected items respectively
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved CheckedListBox es
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.5 ComboBox es Combine TextBox and drop-down list Add method adds object to collection Properties: –DropDownStyle: determines type of ComboBox –Items: returns objects in the list –SelectedItem : returns object selected –SelectedIndex : returns index of selected item
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ComboBox es Click the down arrow to display items in drop- down list Selecting an item from drop-down list changes text in textbox Fig ComboBox demonstration.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ComboBox es
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 4 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 5 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 6 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.6 TreeViews Displays nodes hierarchically Parent nodes have children The first parent node is called the root Use Add method to add nodes
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved TreeViews Click + to expand node and display child nodes Root node Click - to collapse node and hide child nodes Child nodes Fig TreeView displaying a sample tree.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved TreeViews
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved TreeViews
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved TreeViews Fig TreeNode Editor.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 4
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 4
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 4
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 4 of 4
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.7 ListViews Displays list of items –Can select one or more items from list –Displays icons to go along with items
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ListViews
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved ListViews Fig Image Collection Editor window for an ImageList component.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 8
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 8
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 8
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 4 of 8
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 5 of 8
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 6 of 8
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 7 of 8
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 8 of 8
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.8 Tab Control Creates tabbed windows Windows called TabPage objects –TabPages can have controls –Tabpages have own Click event for when tab is clicked
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Tab Control Tab pages Fig Tabbed pages in Visual Studio.NET.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Tab Control TabPage Controls in TabPage TabControl Fig TabControl with TabPages example.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Tab Control Fig TabPages added to a TabControl.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Tab Control
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 4 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 5 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 6 of 6
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.9 Multiple-Document-Interface (MDI) Windows Users can edit multiple documents at once Usually more complex then single-document- interface applications Application window called parent, others child Parent and child menus can be merged –Based on MergeOrder property Child windows can be arranged in parent window: –Tiled windows: completely fill parent, no overlap Either horizontal or vertical –Cascaded windows: overlap, same size, display title bar –ArrangeIcons: arranges icons for minimized windows
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Multiple-Document-Interface (MDI) Windows MDI parent MDI child Fig MDI parent window and MDI child windows.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Multiple-Document-Interface (MDI) Windows Single Document Interface (SDI)Multiple Document Interface (MDI) Fig SDI and MDI forms.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Multiple-Document-Interface (MDI) Windows
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Multiple-Document-Interface (MDI) Windows Parent’s icons: minimize, maximize and close Maximized child’s icons: minimize, restore and close Minimized child’s icons: restore, maximize and close Parent’s title bar displays maximized child Fig Minimized and maximized child windows.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Multiple-Document-Interface (MDI) Windows Separator bar and child windows 9 or more child windows enables the More Windows... option Child windows list Fig MenuItem property MdiList example.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Multiple-Document-Interface (MDI) Windows ArrangeIconsCascade Fig MdiLayout enumeration values. (Part 1)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Multiple-Document-Interface (MDI) Windows TileHorizontalTileVertical Fig MdiLayout enumeration values. (Part 2)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Child.h 1 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Child.h 2 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Child.h 3 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 4 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 5 of 5
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.10 Visual Inheritance Create Form by inheriting from another Form –Derived Form inherits functionality of base Form –Derived Form inherits visual aspects of base Form
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline VisualInhritance.h 1 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline VisualInhritance.h 2 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline VisualInhritance.h 3 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.10 Visual Inheritance inherited components Fig Visual Inheritance displayed in the Form Designer.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 1 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 2 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.h 3 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Form1.cpp 1 of 1
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
13.11 User-Defined Controls Custom controls that inherit from other classes –Ex: can change appearance of a label
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved User-Defined Controls
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved User-Defined Controls Fig Custom-control creation.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved User-Defined Controls Fig Adding a custom control to the ToolBox.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved User-Defined Controls New ToolBox iconl Newly inserted control Fig Custom control added to the ToolBox and a Form.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline ClockControl.h 1 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline ClockControl.h 2 of 3
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline ClockControl.h 3 of 3