 2006 Pearson Education, Inc. All rights reserved. 1 14 Graphical User Interface Concepts: Part 2.

Slides:



Advertisements
Similar presentations
Information System Design Lab 5&6. User Interface Design.
Advertisements

Chapter 1: An Introduction to Visual Basic 2012
What is a Dialog box? A Dialog box is a window or “form” that contains other child windows or “controls” that have a specific appearances and pre-defined.
Using Macros and Visual Basic for Applications (VBA) with Excel
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
MDI windows Single-document-interface (SDI)
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
1 Graphical User Interfaces Part 2 Outline Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
 2009 Pearson Education, Inc. All rights reserved Graphical User Interfaces with Windows Forms: Part 2.
1- Date TimePicker 2- Month Calendar 3- User Defined Controls.
1 Graphical User Interfaces Part 2 Outline ListBoxes and CheckedListBoxes ListBoxes CheckedListBoxes ComboBoxes.
IE 411/511: Visual Programming for Industrial Applications
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
 2009 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2008 IDE.
 2009 Pearson Education, Inc. All rights reserved Dive Into ® Visual C# 2008 Express.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Some Interesting Controls. Controls We've UsedNew Controls LabelListBox TextBoxCheckedListBox ComboBoxTabControl ButtonTabPage Menu MenuItem TreeView.
 2009 Pearson Education, Inc. All rights reserved Graphical User Interfaces with Windows Forms.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline.
Graphical User Interface Concepts - Part 2 Session 09 Mata kuliah: M0874 – Programming II Tahun: 2010.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 - Graphical User Interface Concepts: Part.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Chapter 1 Creating a Dreamweaver Web Page and Local Site
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Chapter Ten Using Controls. 2 Objectives Learn about Controls How to create a Form containing Labels How to set a Label’s Font How to add Color to a.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 2.1 Test-Driving the Welcome Application 2.2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Graphical User Interfaces Part 2 1 Outline TreeViews ListViews Tab Control.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
 2007 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2005 IDE.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Dive Into® Visual Basic 2010 Express
Graphical User Interface
Chapter 2 – Introduction to the Visual Studio .NET IDE
Graphical User Interface Concepts: Part I
Introduction to the Visual C# 2005 Express Edition IDE
Using Procedures and Exception Handling
Chapter 2 – Introduction to the Visual Studio .NET IDE
Windows Forms GUI: A Deeper Look
CIS16 Application Development Programming with Visual Basic
Creating a Windows Forms User Interface
Using Cascading Style Sheets (CSS)
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

 2006 Pearson Education, Inc. All rights reserved Graphical User Interface Concepts: Part 2

 2006 Pearson Education, Inc. All rights reserved. 2 I claim not to have controlled events, but confess plainly that events have controlled me. — Abraham Lincoln Capture its reality in paint! — Paul Cézanne An actor entering through the door, you’ve got nothing. But if he enters through the window, you’ve got a situation. — Billy Wilder

 2006 Pearson Education, Inc. All rights reserved. 3 But, soft! what light through yonder window breaks? It is the east, and Juliet is the sun! — William Shakespeare

 2006 Pearson Education, Inc. All rights reserved. 4 OBJECTIVES In this chapter you will learn:  To create menus, tabbed windows and multiple document interface (MDI) programs.  To use the ListView and TreeView controls for displaying information.  To create hyperlinks using the LinkLabel control.  To display lists of information in ListBox and ComboBox controls.  To input date and time data with the DateTimePicker.  To create custom controls.

 2006 Pearson Education, Inc. All rights reserved Introduction 14.2 Menus 14.3 MonthCalendar Control 14.4 DateTimePicker Control 14.5 LinkLabel Control 14.6 ListBox Control 14.7 CheckedListBox Control 14.8 ComboBox Control 14.9 TreeView Control ListView Control TabControl Control Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls Wrap-Up

 2006 Pearson Education, Inc. All rights reserved Introduction Continue study of GUIs – Menu s Logically organized commands – LinkLabel s Enable user to visit one of several destinations – ListBox – ComboBox es – TreeView Display data hierarchically – TabControl – MDI windows Multiple document interface

 2006 Pearson Education, Inc. All rights reserved Menu s Menu s – Groups of related commands for Windows applications – Integral part of GUIs Organize commands without “cluttering” the GUI – All menu items can have access shortcuts or hotkeys Type an ampersand (&) before the character to be underlined Set the ShortcutKeys property of the appropriate ToolStripMenuItems – Non-top-level menus can also have shortcut keys – Menu items can display check marks Indicates that multiple options on the menu can be selected at once

 2006 Pearson Education, Inc. All rights reserved. 8 Fig | Menus, submenus and menu items Seperator bar Checked menu item Disabled command Shortcut key Submenu Menu items Menu

 2006 Pearson Education, Inc. All rights reserved. 9 Fig | Editing menus in Visual Studio. Main menu bar MenuStrip icon Type menu name in TextBox

 2006 Pearson Education, Inc. All rights reserved. 10 Fig | Adding ToolStripMenuItems to a MenuStrip. TextBoxes for adding items to the menu Place & character before a letter to underline it in the menu, so the character can be used as an access shortcut

 2006 Pearson Education, Inc. All rights reserved. 11 Look-and-Feel Observation 14.1 Buttons can have access shortcuts. Place the & symbol immediately before the desired character in the Button’s label. To press the button by using its access key in the running application, the user presses Alt and the underlined character.

 2006 Pearson Education, Inc. All rights reserved. 12 Fig | Setting a menu item’s shortcut keys. Setting modifier keys Select key (modifier and key combination specifies the shortcut key for the menu item)

 2006 Pearson Education, Inc. All rights reserved. 13 Fig | Menu item options. Menu item options

 2006 Pearson Education, Inc. All rights reserved. 14 Fig | MenuStrip and ToolStripMenuItem properties and an event. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 15 Fig | MenuStrip and ToolStripMenuItem properties and an event. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 16 Look-and-Feel Observation 14.2 It is a convention to place an ellipsis ( ) after the name of a menu item that when selected, displays a dialog (e.g. Save As...). Menu items that produce an immediate action without prompting the user for more information (e.g. Save) should not have an ellipsis following their name.

 2006 Pearson Education, Inc. All rights reserved. 17 Outline MenuTestForm.cs (1 of 8) Event handler for aboutToolStripMenuItem for when it is selected Provide information through a MessageBox Event handler for exitToolStripMenuItem for when it is selected Terminates program

 2006 Pearson Education, Inc. All rights reserved. 18 Outline MenuTestForm.cs (2 of 8) Clears all checkmarks next to the menu items Change the color and check the corresponding menu item

 2006 Pearson Education, Inc. All rights reserved. 19 Outline MenuTestForm.cs (3 of 8) Change the color and check the corresponding menu item

 2006 Pearson Education, Inc. All rights reserved. 20 Outline MenuTestForm.cs (4 of 8) Change the color and check the corresponding menu item Clears all checkmarks next to the menu items

 2006 Pearson Education, Inc. All rights reserved. 21 Outline MenuTestForm.cs (5 of 8) Change the font style and check the corresponding menu item

 2006 Pearson Education, Inc. All rights reserved. 22 Outline MenuTestForm.cs (6 of 8) Change the font style and check the corresponding menu item Bold the current font style if it is not already; else, un-bold it

 2006 Pearson Education, Inc. All rights reserved. 23 (a) (b) Outline MenuTestForm.cs (7 of 8) Italicize the current font style if it is not already; else, un-italicize it

 2006 Pearson Education, Inc. All rights reserved. 24 Outline MenuTestForm.cs (8 of 8) (c) (d) (e) (f)

 2006 Pearson Education, Inc. All rights reserved. 25 Software Engineering Observation 14.1 The mutual exclusion of menu items is not enforced by the MenuStrip, even when the Checked property is true. You must program this behavior.

 2006 Pearson Education, Inc. All rights reserved MonthCalendar Control The.NET Framework provides two controls that allow an application to retrieve date and time information – MonthCalendar Displays a monthly calendar on the Form The default event for this control is DateChanged – Generated when a new date is selected – DateTimePicker (Section 14.4)

 2006 Pearson Education, Inc. All rights reserved. 27 Fig | MonthCalendar control. Current day is outlined Selected day is highlighted

 2006 Pearson Education, Inc. All rights reserved. 28 Fig | MonthCalendar properties and an event.

 2006 Pearson Education, Inc. All rights reserved DateTimePicker Control DateTimePicker – Displays the calendar when a down arrow is selected – Retrieve date and time information from user – More customizable than a MonthCalendar More properties are provided to edit the look and feel of the drop-down calendar – ValueChanged event Occurs when user selects a date

 2006 Pearson Education, Inc. All rights reserved. 30 Fig | DateTimePicker properties and an event. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 31 Fig | DateTimePicker properties and an event. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 32 Outline DateTimePickerForm.cs (1 of 3) Retrieve the date selected by the user Update outputLabel : Print the 3 rd day after user’s selected date Update outputLabel : Print the 2 nd day after user’s selected date

 2006 Pearson Education, Inc. All rights reserved. 33 Outline DateTimePickerForm.cs (2 of 3) (a)(b) The “minimum” date that can be selected is “today” The “maximum” date that can be selected is a year from “today”

 2006 Pearson Education, Inc. All rights reserved. 34 Outline DateTimePickerForm.cs (3 of 3) (c)(d)

 2006 Pearson Education, Inc. All rights reserved LinkLabel Control LinkLabel – Displays links to other resources Ex: files or Web pages – LinkClicked event Generated when LinkLabel clicked – Class LinkLabel is derived from class Label Inherits all of class Label ’s functionality symbol before a string indicates that all characters should be interpreted literally Class Process – Method Start Allows you to execute other programs from an application

 2006 Pearson Education, Inc. All rights reserved. 36 Look-and-Feel Observation 14.3 A LinkLabel is the preferred control for indicating that the user can click a link to jump to a resource such as a Web page, though other controls can perform similar tasks.

 2006 Pearson Education, Inc. All rights reserved. 37 Fig | LinkLabel control in running program. Hand image displays when mouse moves over LinkLabel LinkLabel on a Form

 2006 Pearson Education, Inc. All rights reserved. 38 Fig | LinkLabel properties and an event. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 39 Fig | LinkLabel properties and an event. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 40 Outline LinkLabelTestForm. cs (1 of 4) Change the color of the link to show that it has already been clicked before Open the C: folder

 2006 Pearson Education, Inc. All rights reserved. 41 Outline LinkLabelTestForm. cs (2 of 4) Change the color of the link to show that it has already been clicked before Open Internet Explorer and visit the site Change the color of the link to show that it has already been clicked before Open new document in NotePad

 2006 Pearson Education, Inc. All rights reserved. 42 Outline LinkLabelTestForm. cs (3 of 4) Click first LinkLabel to look at contents of C: drive

 2006 Pearson Education, Inc. All rights reserved. 43 Outline LinkLabelTestForm. cs (4 of 4) Click second Linklabel to go to Deitel Web site Click on third Linklabel to open Notepad

 2006 Pearson Education, Inc. All rights reserved ListBox Control ListBox – Allows user to view and select from multiple items in a list – Static GUI entities – To add and remove items Call the Add method Call the AddRange method – Add an array of objects Call the RemoveAt method Call the Clear method – Remove all entries Use the String Collection Editor

 2006 Pearson Education, Inc. All rights reserved. 45 Fig | ListBox and CheckedListBox on a Form. CheckedListBox ListBox Scrollbars appear if necessary Selected items Checked item

 2006 Pearson Education, Inc. All rights reserved. 46 Fig | ListBox properties, methods and an event. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 47 Fig | ListBox properties, methods and an event. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 48 Fig | String Collection Editor.

 2006 Pearson Education, Inc. All rights reserved. 49 Outline ListBoxTestForm.cs (1 of 3) Add user’s input as a new element of displayListBox

 2006 Pearson Education, Inc. All rights reserved. 50 Outline ListBoxTestForm.cs (2 of 3) Remove the selected element from displayListBox Remove every element from displayListBox Terminate program

 2006 Pearson Education, Inc. All rights reserved. 51 Outline ListBoxTestForm.cs (3 of 3) (a) (b) (c) (d)

 2006 Pearson Education, Inc. All rights reserved CheckListBox Control CheckListBoxes – Extend ListBox – Include CheckBox es next to each item in the list – Multiple items can be selected – SelectionMode property Only possible values are None and One – Give the user multiple selection or no selection at all Behavior consistent with that of CheckBox es – Event ItemCheck Occurs whenever a user checks or unchecks a CheckedListBox item

 2006 Pearson Education, Inc. All rights reserved. 53 Common Programming Error 14.1 The IDE displays an error message if you attempt to set the SelectionMode property to MultiSimple or MultiExtended in the Properties window of a CheckedListBox. If this value is set programmatically, a runtime error occurs.

 2006 Pearson Education, Inc. All rights reserved. 54 Fig | CheckedListBox properties, methods and events. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 55 Fig | CheckedListBox properties, methods and events. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 56 CheckedListBoxTest Form.cs (1 of 3) Outline Retrieve the selected element as a string Add the retrieved element to displayListBox Remove the retrieved element to displayListBox

 2006 Pearson Education, Inc. All rights reserved. 57 Outline CheckedListBoxTest Form.cs (2 of 3) (a) (b)

 2006 Pearson Education, Inc. All rights reserved. 58 Outline (c) (d) CheckedListBoxTest Form.cs (3 of 3)

 2006 Pearson Education, Inc. All rights reserved ComboBox Control ComboBox – Combines TextBox features with a drop-down list – Contains a list from which a value can be selected – User can enter text into the TextBox – User can click the down arrow to select from a list of predefined items

 2006 Pearson Education, Inc. All rights reserved. 60 Fig | ComboBox demonstration. Click the down arrow to display items in drop-down list Selecting an item from drop-down list changes text in TextBox portion

 2006 Pearson Education, Inc. All rights reserved. 61 Look-and-Feel Observation 14.4 Use a ComboBox to save space on a GUI. A disadvantage is that, unlike with a ListBox, the user cannot see available items without expanding the drop-down list.

 2006 Pearson Education, Inc. All rights reserved. 62 Fig | ComboBox properties and an event. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 63 Fig | ComboBox properties and an event. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 64 Outline comboBoxTextForm.Cs (1 of 3) Create all the necessary objects for drawing

 2006 Pearson Education, Inc. All rights reserved. 65 Outline comboBoxTextForm.Cs (2 of 3) Property that returns the index of the selected element Chooses and draw the appropriate shape based on the user’s selection

 2006 Pearson Education, Inc. All rights reserved. 66 Outline comboBoxTextForm.Cs (3 of 3) (a) (b) (c)(d)

 2006 Pearson Education, Inc. All rights reserved. 67 Look-and-Feel Observation 14.5 Make lists (such as ComboBoxes ) editable only if the program is designed to accept user-submitted elements. Otherwise, the user might try to enter a custom item that is improper for the purposes of your application.

 2006 Pearson Education, Inc. All rights reserved TreeView Control TreeView – Displays nodes hierarchically in a tree Nodes are objects that contain values and can refer to other nodes – A parent node contains child nodes – Child nodes can be parents to other nodes – Child nodes with the same parent node are considered sibling nodes A tree is a collection of nodes organized in a hierarchical manner – The first parent node of a tree is the root node – The nodes in a TreeView are instances of class TreeNode Each TreeNode has a Nodes collection – Contains a list of other TreeNode s Parent property – Returns a reference to the parent node – Returns null if the node is a root node

 2006 Pearson Education, Inc. All rights reserved. 69 Fig | TreeView displaying a sample tree. Click + to expand node and display child nodes Root node Click - to collapse node and hide child nodes Child nodes (of Manager2)

 2006 Pearson Education, Inc. All rights reserved. 70 Fig | TreeView properties and an event.

 2006 Pearson Education, Inc. All rights reserved. 71 Fig | TreeNode properties and methods. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 72 Fig | TreeNode properties and methods. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved TreeView Control (Cont.) TreeView – Adding nodes TreeNode Editor Call method Add

 2006 Pearson Education, Inc. All rights reserved. 74 Fig | TreeNode Editor. Delete current node

 2006 Pearson Education, Inc. All rights reserved. 75 Outline TreeViewDirectoryS tructureForm.cs (1 of 4) An array of strings representing directories

 2006 Pearson Education, Inc. All rights reserved. 76 Outline TreeViewDirectoryS tructureForm.cs (2 of 4) Create an object of TreeNode for the current directory Append the current directory to the parent directory Continue process for the rest of the subdirectories

 2006 Pearson Education, Inc. All rights reserved. 77 Outline TreeViewDirectoryS tructureForm.cs (3 of 4) Unauthorized access of directories Check to see if the user specified directory exist or not Append directory to directoryTreeView Add the subdirectories

 2006 Pearson Education, Inc. All rights reserved. 78 Outline TreeViewDirectoryS tructureForm.cs (4 of 4) (a) (b) Notify user that the directory does not exist

 2006 Pearson Education, Inc. All rights reserved ListView Control ListView – Similar to ListBox Both display lists from which the user can select one or more items – Difference between the two classes is that a ListView can display icons next to the list items Allows you to define the images used as icons for ListView items – To display images, an ImageList component is required

 2006 Pearson Education, Inc. All rights reserved. 80 Fig | ListView properties and an event. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 81 Fig | ListView properties and an event. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 82 Fig | Image Collection Editor window for an ImageList component.

 2006 Pearson Education, Inc. All rights reserved. 83 Outline ListViewTestForm.cs (1 of 7) Retrieve the current project’s directory

 2006 Pearson Education, Inc. All rights reserved. 84 Outline ListViewTestForm.cs (2 of 7) Get the number of selected items Load the parent’s directory Create an object that holds the information for the directory

 2006 Pearson Education, Inc. All rights reserved. 85 Outline ListViewTestForm.cs (3 of 7) Load the selected directory Update displayLabel with the current directory

 2006 Pearson Education, Inc. All rights reserved. 86 Outline ListViewTestForm.cs (4 of 7) Remove all elements from browserListView Add an element to go back to the parent directory Update the current directory information Store all of the current directory’s files and subdirectories Add all the current directory’s subdirectories to ListView Specify which image to use for the directories

 2006 Pearson Education, Inc. All rights reserved. 87 Outline ListViewTestForm.cs (5 of 7) Add all the current directory’s files to ListView Specify which image to use for the files Notify user of unauthorized access

 2006 Pearson Education, Inc. All rights reserved. 88 Outline ListViewTestForm.cs (6 of 7) (a) Specify the images associated with directories and files Initially, load program with the current project’s directory

 2006 Pearson Education, Inc. All rights reserved. 89 Outline ListViewTestForm.cs (7 of 7) (b) (c)

 2006 Pearson Education, Inc. All rights reserved. 90 Software Engineering Observation 14.2 When designing applications that run for long periods of time, you might choose a large initial delay to improve performance throughout the rest of the program. However, in applications that run for only short periods of time, developers often prefer fast initial loading times and small delays after each action.

 2006 Pearson Education, Inc. All rights reserved TabControl Control TabControl – Creates tabbed windows – Specify more information in the same amount of space – Contain TabPage objects Add controls to the TabPage objects Add the TabPage s to the TabControl Only one TabPage is displayed at a time To view different TabPage s click the appropriate tab – Click event Generated when TabPage ’s tab is clicked

 2006 Pearson Education, Inc. All rights reserved. 92 Fig | Tabbed windows in Visual Studio. Tab windows

 2006 Pearson Education, Inc. All rights reserved. 93 Fig | TabControl with TabPages example. TabPage Controls in TabPage TabControl

 2006 Pearson Education, Inc. All rights reserved. 94 Fig | TabPage s added to a TabControl.

 2006 Pearson Education, Inc. All rights reserved. 95 Fig | TabControl properties and an event.

 2006 Pearson Education, Inc. All rights reserved. 96 Outline UsingTabsForm.cs (1 of 4) Change font color of displayLabel to black Change font color of displayLabel to red

 2006 Pearson Education, Inc. All rights reserved. 97 Outline UsingTabsForm.cs (2 of 4) Change font color of displayLabel to green Change font size to 12 Change font size to 16

 2006 Pearson Education, Inc. All rights reserved. 98 Outline UsingTabsForm.cs (3 of 4) Change font size to 20 Output “Hello!” Output “Goodbye!”

 2006 Pearson Education, Inc. All rights reserved. 99 Outline UsingTabsForm.cs (4 of 4) (a) (b) (c) (d)

 2006 Pearson Education, Inc. All rights reserved. 100 Software Engineering Observation 14.3 A TabPage can act as a container for a single logical group of RadioButtons, enforcing their mutual exclusivity. To place multiple RadioButton groups inside a single TabPage, you should group RadioButtons within Panels or GroupBoxes contained within the TabPage.

 2006 Pearson Education, Inc. All rights reserved Multiple Document Interface (MDI) Windows Multiple Document Interface (MDI) – Parent window Main application window Only one in application – Child window Each window inside the application Only one child can be active at a time Cannot also be a parent window As many child windows as you want

 2006 Pearson Education, Inc. All rights reserved. 102 Fig | MDI parent window and MDI child windows. MDI parent MDI child

 2006 Pearson Education, Inc. All rights reserved. 103 Fig | SDI and MDI forms. Single Document Interface (SDI) Multiple Document Interface (MDI)

 2006 Pearson Education, Inc. All rights reserved Multiple Document Interface (MDI) Windows (Cont.) Creating an MDI Form – Create a new Form Set its IsMdiContainer property to true – Create a child Form Add the child Form to the parent – Set its MdiParent property to the parent Form Call the child Form ’s Show method – To add a child Form to a parent, write: ChildFormClass childForm = New ChildFormClass(); childForm.MdiParent = parentForm; childForm.Show();

 2006 Pearson Education, Inc. All rights reserved. 105 Fig | MDI parent and MDI child properties, method and event.

 2006 Pearson Education, Inc. All rights reserved. 106 Good Programming Practice 14.1 When creating MDI applications, include a menu that displays a list of the open child windows. This helps the user select a child window quickly, rather than having to search for it in the parent window.

 2006 Pearson Education, Inc. All rights reserved. 107 Fig | Minimized and maximized child windows. (a)(b) Parent window icons: minimize,maximize and close Maximized child window icons: minimize, restore and close Parent title bar indicates maximized child Minimized child window icons: restore, maximize and close

 2006 Pearson Education, Inc. All rights reserved. 108 Fig | MenuItem property MdiList example. 9 or more child windows enables the More Windows… option Child windows list

 2006 Pearson Education, Inc. All rights reserved. 109 Fig | MdiLayout enumeration values. (c) TileHorizontal (a) ArrangeIcons (b) Cascade (d) Tilevertical

 2006 Pearson Education, Inc. All rights reserved. 110 Outline UsingMDIForm.cs (1 of 4) Create a new child form Set this form to be the child form’s parent Show the child form

 2006 Pearson Education, Inc. All rights reserved. 111 Outline UsingMDIForm.cs (2 of 4) Create another new child form Set this form to be the child form’s parent Show the child form Create another new child form Set this form to be the child form’s parent Show the child form Terminate program

 2006 Pearson Education, Inc. All rights reserved. 112 Outline UsingMDIForm.cs (3 of 4) Specify how to display the child forms on the MDI parent form

 2006 Pearson Education, Inc. All rights reserved. 113 Outline UsingMDIForm.cs (4 of 4) (a) (b) (c) (d)

 2006 Pearson Education, Inc. All rights reserved. 114 Outline ChildForm.cs ChildForm’s constructor Display the image specified by the filename

 2006 Pearson Education, Inc. All rights reserved Visual Inheritance Visual Inheritance – Enables to achieve visual consistency across applications – All Form s created so far derives from class System.Windows.Forms.Form – Derived Form s contains the functionality of its base class Form Includes any base-class properties, methods, variables and controls – The derived class also inherits all visual aspects Ex: sizing, component layout, spacing between GUI components, colors and fonts

 2006 Pearson Education, Inc. All rights reserved. 116 Outline VisualInheritanceF orm.cs VisualInheritanceForm inherits from Form Display MessageBox

 2006 Pearson Education, Inc. All rights reserved. 117 Fig | Form demonstrating visual inheritance.

 2006 Pearson Education, Inc. All rights reserved. 118 Outline VisualInheritanceT estForm.cs (1 of 2) VisualInheritanceFormTest inherits from VisualInheritanceForm Display MessageBox

 2006 Pearson Education, Inc. All rights reserved. 119 Outline VisualInheritanceT estForm.cs (2 of 2) Derived class cannot modify these controls. Derived class can modify this control.

 2006 Pearson Education, Inc. All rights reserved User-Defined Controls User-Defined Controls –.NET Framework allow you to create custom controls Appear in the user’s Toolbox Can be added to Forms, Panels or GroupBoxes in the same way that we add other predefined controls – The simplest way to create a custom control is to derive a class from an existing control Useful if you want to add functionality to an existing control

 2006 Pearson Education, Inc. All rights reserved User-Defined Controls (Cont.) – Method OnPaint Contained by all controls Called when a component must be redrawn Passed a PaintEventArgs object The derived control’s OnPaint method is called through polymorphism The base class’s OnPaint implementation is not called – Must call it explicitly from the new OnPaint implementation before we execute our custom-paint code Ensure the control will be displayed correctly

 2006 Pearson Education, Inc. All rights reserved User-Defined Controls (Cont.) – UserControl Create a new control composed of existing controls Acts as a container for the controls added to it Contains constituent controls – Controls added to a custom control – Does not determine how these constituent controls are displayed – Method OnPaint of the UserControl Cannot be overridden – To control the appearance of each constituent control, you must handle each control’s Paint event The Paint event handler is passed a PaintEventArgs object

 2006 Pearson Education, Inc. All rights reserved User-Defined Controls (Cont.) – Create a brand new control by inheriting from class Control Does not define any specific behavior Control handles the items associated with all controls – Ex: events and sizing handles Method OnPaint – Should contain a call to the base class’s OnPaint method – Add code that draws custom graphics inside the overridden OnPaint method

 2006 Pearson Education, Inc. All rights reserved. 124 Fig | Custom control creation.

 2006 Pearson Education, Inc. All rights reserved. 125 Outline ClockUserControl.cs Update time to displayLabel at every tick event

 2006 Pearson Education, Inc. All rights reserved User-Defined Controls (Cont.) Share custom controls with other developers (Example: UserControl ) – Create a new Class Library project. – Delete Class1.cs, initially provided with the application. – Right click the project in the Solution Explorer and select Add > User Control. – Inside the project, add controls and functionality to the UserControl. – Build the project. – Create a new Windows application. – Right click the ToolBox and select Choose Items. In the Choose Toolbox Items dialog, click Browse. Browse for the.dll file from the class library created. The item will then appear in the Choose Toolbox Items dialog. If it is not already checked, check this item. Click OK to add the item to the Toolbox. This control can now be added to the Form as if it were any other control.

 2006 Pearson Education, Inc. All rights reserved. 127 Fig | Custom-control creation.

 2006 Pearson Education, Inc. All rights reserved. 128 Fig | Custom control added to the ToolBox.

 2006 Pearson Education, Inc. All rights reserved. 129 Fig | Custom control added to a Form. New ToolBox icon Newly inserted control