Jozef Goetz contribution, 2012 1  2011 Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved.

Slides:



Advertisements
Similar presentations
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.
Advertisements

 2006 Pearson Education, Inc. All rights reserved Graphical User Interface Concepts: Part 2.
© 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,
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 3 1 Microsoft Office Excel 2003 Tutorial 3 – Developing a Professional- Looking.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
 2007 Dr. Natheer Khasawneh. All rights reserved. 1 Chapter 14 – Graphical User Interfaces Part 2 Outline 14.9 TreeViews ListViews TabControl.
MDI windows Single-document-interface (SDI)
Chapter 13: Advanced GUI and Graphics
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Chapter 4: Working with Windows Types of Windows –Program Windows –Message Boxes –Dialog Boxes Elements of a Window –Window Panes –Scroll Bars –Menus –Tool.
BİL528 – Bilgisayar Programlama II Advanced Controls, Menus, Toolbars, and Status Bars 1.
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.
BIM313 – Advanced Programming Simple Controls 1. Contents Traditional Controls – Labels, Text Boxes, Buttons, Check Boxes, List Boxes, Combo Boxes Advanced.
1 Graphical User Interfaces Part 2 Outline Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
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.
CSCI 3327 Visual Basic Chapter 10: Windows Forms GUI: A Deeper Look UTPA – Fall 2011.
IE 411/511: Visual Programming for Industrial Applications
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.
Microsoft Office Excel 2003 Tutorial 3 – Developing a Professional-Looking Worksheet.
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.
Windows Tutorial Common Objects ACOS: 1, 4. Using the Taskbar 1. Using the taskbar, you can switch between open programs and between open documents within.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline.
C # Graphical User Interfaces BIT-7 Saad Liaquat.
Graphical User Interface Concepts - Part 2 Session 09 Mata kuliah: M0874 – Programming II Tahun: 2010.
Copyright © 2010 Wolters Kluwer Health | Lippincott Williams & Wilkins Introduction to Windows Chapter 2.
© 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.
 2002 Prentice Hall. All rights reserved. 1 Chapter 13 – Graphical User Interfaces Part 2 Outline 13.1 Introduction 13.2 Menus 13.3 LinkLabels 13.4 ListBoxes.
Lesson 11: Looking at Files and Folders what a file or folder is on the computer how to recognize a file or folder on the desktop how to recognize the.
Basic Editing Lesson 2.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
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.
 2002 Prentice Hall. All rights reserved. 1 Chapter 13 – Graphical User Interfaces Part 2 Outline 13.1 Introduction 13.2 Menus 13.3 LinkLabels 13.4 ListBoxes.
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.
Jozef Goetz contribution,  Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved.
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.
 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.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
Dive Into® Visual Basic 2010 Express
Graphical User Interface
Chapter 13 – Graphical User Interfaces Part 2
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
Graphical User Interfaces Part 2
Using Procedures and Exception Handling
Chapter 2 – Introduction to the Visual Studio .NET IDE
Windows Forms GUI: A Deeper Look
DREAMWEAVER MX 2004 Chapter 3 Working with Tables
Chapter 4 Enhancing the Graphical User Interface
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

Jozef Goetz contribution,  2011 Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved.

Jozef Goetz contribution,  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

Jozef Goetz contribution,  But, soft! what light through yonder window breaks? It is the east, and Juliet is the sun!  William Shakespeare

Jozef Goetz contribution, Chapter 15 – Graphical User Interfaces Part 2 Outline 15.1 Introduction 15.2 Menus 15.3 MonthCalendar 15.4 DateTimePicker 15.5 LinkLabels 15.6 ListBoxes 15.7 CheckedListBoxes 15.8 ComboBoxes 15.9 TreeViews ListViews 15.11Tab Control Multiple Document Interface (MDI) Windows 15.13Visual Inheritance User-Defined Controls

Jozef Goetz contribution, Chapter 15: Graphical User Interface Concepts: Part 2: Objectives 1.To be able to create menus, window tabs and multiple-document-interface (MDI) programs. 2.To understand the use of the ListView and TreeView controls for displaying information. 3.To be able to use hyperlinks with the LinkLabel control. 4.To be able to display lists using ListBoxes and ComboBoxes. 5.To create custom controls.

Jozef Goetz contribution, Introduction  Visual Studio provides a large set of GUI components.  Visual Studio also enables you to design custom controls and add them to the ToolBox  Continues study of Graphical User Interface  Explores:  Menus  LinkLabels  ListBox  CheckedListBox  ComboBoxes  TreeView control  Tab controls  Multiple-document interface MDI windows

Jozef Goetz contribution,  Menus provide groups of related commands (Fig. 15.1).  Menus organize commands without “cluttering” the GUI. Fig | Menus, submenus and menu items. Checked menu item Submenu Separator bar Shortcut key Disabled commands Menu Menu items Menu icons 15.2 Menus

Jozef Goetz contribution,  To create a menu, open the Toolbox and drag a MenuStrip control onto the Form.  To add menu items to the menu, click the Type Here TextBox (Fig. 15.2) and type the menu item’s name. Fig | Editing menus in Visual Studio. MenuStrip icon Type menu name in TextBox Main menu bar 15.2 Menus

Jozef Goetz contribution,  After you press the Enter key, the menu item is added.  More Type Here TextBox es allow you to add more items (Fig. 15.3). Fig | Adding ToolStripMenuItems to a MenuStrip. Place & character before a letter to underline it in the menu, so the character can be used as an access shortcut TextBoxes for adding items to the menu 15.2 Menus

Jozef Goetz contribution,  Menus can have Alt key shortcuts which are accessed by pressing Alt and the underlined letter.  To make the File menu item have a key shortcut, type &File.  The letter F is underlined to indicate that it is a shortcut Menus

Jozef Goetz contribution,  Menu items can have shortcut keys as well (Ctrl, Shift, Alt, F1, F2, letter keys, and so on).  To add other shortcut keys, set the ShortcutKeys property (Fig. 15.4). Fig | Setting a menu item’s shortcut keys. Select key (modifier and key combination specifies the shortcut key for the menu item) Setting modifier keys 15.2 Menus

Jozef Goetz contribution, Look-and-Feel Observation 15.1  Buttons can have access keyboard 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.  You can remove a menu item by selecting it with the mouse and pressing the Delete key.  Menu items can be grouped by separator bars, which are inserted by right clicking and selecting Insert Separator or by typing “ - ” for the text of a menu item.

Jozef Goetz contribution, Fig | Menu-item options. Menu item options Visual Studio allows you to add TextBox es and ComboBox es as menu items. Before you enter text for a menu item, you are provided with a drop-down list. – Clicking the down arrow allows you to select the type of item to add (Fig. 15.5) Menus

Jozef Goetz contribution, 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)

Jozef Goetz contribution, Fig | Menu item options. Menu item options

Jozef Goetz contribution, Fig | MenuStrip and ToolStripMenuItem properties and an event. (Part 1 of 2.)

Jozef Goetz contribution, Fig | MenuStrip and ToolStripMenuItem properties and an event. (Part 2 of 2.)

Jozef Goetz contribution, Look-and-Feel Observation 15.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.

Jozef Goetz contribution,  MenuTestForm.cs  (1 of 8) (c)(c) (d)(d) (e)(e) (f)(f) displayLabel.Text is preset manually in class

Jozef Goetz contribution, Outline  MenuTestF orm.cs  (2 of 8) (c)(c) (d)(d) (e)(e) (f )

Jozef Goetz contribution, Outline  MenuTestF orm.cs  (3 of 8) (c)(c) (d)(d) (e)(e) (f )

Jozef Goetz contribution, Outline  MenuTestF orm.cs  (4 of 8) (c)(c) (d)(d) (e)(e) (f )

Jozef Goetz contribution, Outline  MenuTestF orm.cs  (5 of 8) (a) (b)

Jozef Goetz contribution, Outline  MenuTestF orm.cs  (6 of 8) (a) (b)

Jozef Goetz contribution, (a) (b) Outline  MenuTestF orm.cs  (7 of 8)

Jozef Goetz contribution, Outline  MenuTestF orm.cs  (8 of 8) (c) (d) (e) (f)

Jozef Goetz contribution, Software Engineering Observation 15.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 Menus

Jozef Goetz contribution, Fig | MonthCalendar control. Current day is outlined Selected day is highlighted

Jozef Goetz contribution,  The MonthCalendar control (Fig. 15.8) displays a monthly calendar on the Form.  Multiple dates can be selected by clicking dates on the calendar while holding down the Shift key. Fig | MonthCalendar control. Current day is outlined Selected day is highlighted Fig | MonthCalendar control.

Jozef Goetz contribution, Fig | MonthCalendar properties and an event.

Jozef Goetz contribution, Fig | DateTimePicker properties and an event. (Part 1 of 2.)  The DateTimePicker control displays a calendar when a down arrow is selected.  The DateTimePicker can be used to retrieve date and time information from the user.

Jozef Goetz contribution, Fig | DateTimePicker properties and an event. (Part 2 of 2.)

Jozef Goetz contribution, Outline  DateTimePickerForm.cs (c)(d) The DateTime structure’s DayOfWeek property determines the day of the week on which the selected date falls. Retrieving the selected date from the Value property. Using DateTime ’s AddDays method to increase the date by two days or three days. the arrival date is always two days after drop-off, or three days if a Sunday is reached.

Jozef Goetz contribution, Outline  DateTimePickerForm.cs Fig | Demonstrating DateTimePicker. (Part 4 of 4.) a) Clicking the down arrow b) Selecting a day from the calendar c) The Label updates d) Selecting another day Setting the MinDate and MaxDate properties to keep drop-off sometime in the next year.

Jozef Goetz contribution, LinkLabels  LinkLabel  Displays links to other resources  Files  Web pages  Behavior similar to web page hyperlink  Can change color –New –Previously visited

Jozef Goetz contribution, LinkLabel s Fig LinkLabel control in the design phase and in running program. LinkLabel on a form Hand image displayed when mouse cursor over a LinkLabel

Jozef Goetz contribution,  The LinkLabel control displays links to other resources, such as files or web pages (Fig ). Fig | LinkLabel control in running program. Look-and-Feel Observation 15.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. LinkLabel on a Form Hand image displays when mouse moves over LinkLabel 15.5 LinkLabel Control

Jozef Goetz contribution, LinkLabel s  Represents a Windows label control that can display hyperlinks.  For a list of all members of this type, see LinkLabel Members.LinkLabel Members  System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.Label System.Windows.Forms.LinkLabel System.ObjectSystem.MarshalByRefObjectSystem.ComponentModel.ComponentSystem.Windows.Forms.ControlSystem.Windows.Forms.Label  like a hyperlink in a Web page  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

Jozef Goetz contribution, LinkLabel s

 2002 Prentice Hall. All rights reserved. Outline 40 LinkLabelTest.cs 1 // Fig ed1 or ed4: LinkLabelTest.cs 2 // Using LinkLabels to create hyperlinks. 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; public class LinkLabelTest : System.Windows.Forms.Form 12 { 13 // linklabels to C: drive, and Notepad 14 private System.Windows.Forms.LinkLabel driveLinkLabel; 15 private System.Windows.Forms.LinkLabel deitelLinkLabel; 16 private System.Windows.Forms.LinkLabel notepadLinkLabel; [STAThread] 19 static void Main() 20 { 21 Application.Run( new LinkLabelTest() ); 22 } // browse C:\ drive 25 private void driveLinkLabel_LinkClicked( object sender, 26 System.Windows.Forms.LinkLabelLinkClickedEventArgs e ) 27 { 28 driveLinkLabel.LinkVisited = true; 29 System.Diagnostics.Process.Start( "C:\\" ); in indicates that all characters in the string should be interprated literally – this is known as a verbatim string 30 } 31 C drive linkNotepad linkDeitel website link C drive event handler Start method to open other programs in class

 2002 Prentice Hall. All rights reserved. Outline // load in Web broswer 33 private void deitelLinkLabel_LinkClicked( object sender, 34 System.Windows.Forms.LinkLabelLinkClickedEventArgs e ) 35 { 36 deitelLinkLabel.LinkVisited = true; 37 System.Diagnostics.Process.Start( 38 "IExplore", " ); // or just the 2 nd parameter 39 } // run application Notepad 42 private void notepadLinkLabel_LinkClicked( 43 object sender, 44 System.Windows.Forms.LinkLabelLinkClickedEventArgs e ) 45 { 46 notepadLinkLabel.LinkVisited = true; // program called as if in run 49 // menu and full path not needed 50 System.Diagnostics.Process.Start( "notepad" ); 51 } } // end class LinkLabelTest Deitel website event handler Notepad event handler System.Diagnostics.Process - Provides access to local and remote processes and enables you to start and stop local system processes. System.Object System.MarshalByRefObject System.ComponentModel.Component System.Diagnostics.Process 1.Process.Start(ProcessStartInfo) - Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new Process component. 2.Process.Start(String) - Starts a process resource by specifying the name of a document or application file and associates the resource with a new Process component. 3.Process.Start(String, String) - Starts a process resource by specifying the name of an application and a set of command line arguments, and associates the resource with a new Process component.

Jozef Goetz contribution, Outline Fig | LinkLabel s used to link to a drive, a web page and an application. (Part 4 of 6.) Click first LinkLabel to look at contents of C: drive LinkLabelTest Form.cs (4 of 6 )

Jozef Goetz contribution, Outline Fig | LinkLabel s used to link to a drive, a web page and an application. (Part 5 of 6.) Click second LinkLabel to go to Deitel website LinkLabelTest Form.cs (5 of 6 )

Jozef Goetz contribution, Outline Fig | LinkLabel s used to link to a drive, a web page and an application. (Part 6 of 6.) Click on third LinkLabel to open Notepad LinkLabelTest Form.cs (6 of 6 )

Jozef Goetz contribution, ListBox es and CheckListBox es Fig ListBox and CheckedListBox on a form. ListBox Selected Items Checked item CheckedListBox Scroll bars appear if necessary Extends ListBox by placing check boxes next to items Can select more than one object at one time allows the user to view and select from multiple items in a list

Jozef Goetz contribution, ListBox es  ListBoxe s  Allow users to view and select from items on a list  Static objects – static GUI entities  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  Event: SelectedIndexChanged – generated when selected index changes For a list of all members of this type, see ListBox Members.ListBox Members System.Object System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ListControl System.Windows.Forms.ListBox System.Windows.Forms.CheckedListBoxSystem.MarshalByRefObjectSystem.ComponentModel.ComponentSystem.Windows.Forms.ControlSystem.Windows.Forms.ListControlSystem.Windows.Forms.CheckedListBox

Jozef Goetz contribution, ListBox es

Jozef Goetz contribution, Fig | ListBox properties, methods and an event. (Part 2 of 2.)

Jozef Goetz contribution, ListBox es Fig String Collection Editor. Use Add method to add to Items collection myListBox.Items.Add(“myListItem”) or Using the Items property by clicking the ellipsis we can add as the following editor is open up A Collection is a data structure, similar to an array and can be used with a foreach statement.

 2002 Prentice Hall. All rights reserved. Outline 50 in class 1 // Fig 13.11:ed1 or ed4 ListBoxTest.cs 2 // Program to add, remove and clear list box items. 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; public class ListBoxTest : System.Windows.Forms.Form 12 { 13 // contains user-input list of elements 15 private System.Windows.Forms.ListBox displayListBox; // user input textbox 17 private System.Windows.Forms.TextBox inputTextBox; // add, remove, clear and exit command buttons 20 private System.Windows.Forms.Button addButton; 21 private System.Windows.Forms.Button removeButton; 22 private System.Windows.Forms.Button clearButton; 23 private System.Windows.Forms.Button exitButton; [STAThread] 26 static void Main() 27 { 28 Application.Run( new ListBoxTest() ); 29 } 30 Display ListBoxText field for inputAdd button Remove Button Clear button Exit button Below developed Class ListBoxTest Allows users to add and remove items from ListBox Uses event handlers to add to, remove from and clear list

 2002 Prentice Hall. All rights reserved. Outline 51 ListBoxTest.cs 31 // add new item (text from input box) 32 // and clear input box 33 private void addButton_Click( 34 object sender, System.EventArgs e ) 35 { 36 displayListBox.Items.Add( inputTextBox.Text ); 37 inputTextBox.Clear(); 38 } // remove item if one selected 41 private void removeButton_Click( 42 object sender, System.EventArgs e ) 43 { 44 // remove only if item selected 45 if ( displayListBox.SelectedIndex != -1 ) 46 displayListBox.Items.RemoveAt( 47 displayListBox.SelectedIndex ); 48 } // clear all items 51 private void clearButton_Click( 52 object sender, System.EventArgs e ) 53 { 54 displayListBox.Items.Clear(); 55 } // exit application 58 private void exitButton_Click( 59 object sender, System.EventArgs e ) 60 { 61 Application.Exit(); 62 } } // end class ListBoxTest Add event handler Add method Remove methodClear methodTest if item is selected Exit

 2002 Prentice Hall. All rights reserved. Outline 52 ListBoxTest.cs Program Output

Jozef Goetz contribution, CheckedListBox es  Displays a ListBox in which a check box is displayed to the left of each item.ListBox  For a list of all members of this type, see CheckedListBox Members.CheckedListBox Members  System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ListControl System.Windows.Forms.ListBox System.Windows.Forms.CheckedListBox System.ObjectSystem.MarshalByRefObjectSystem.ComponentModel.ComponentSystem.Windows.Forms.ControlSystem.Windows.Forms.ListControlSystem.Windows.Forms.ListBox  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

Jozef Goetz contribution, CheckListBox es

Jozef Goetz contribution, CheckListBox es  System.Windows.Forms Namespace has  public enum CheckState.Checked  Specifies the state of a control, such as a check box, that can be checked, unchecked, or set to an indeterminate state.

 2002 Prentice Hall. All rights reserved. Outline 56 CheckedListBoxTe st.cs 1 // Fig ed1 or ed3: CheckedListBoxTest.cs 2 // Using the checked list boxes to add items to a list box 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; public class CheckedListBoxTest : System.Windows.Forms.Form 12 { 13 // list of available book titles 14 private System.Windows.Forms.CheckedListBox 15 inputCheckedListBox; // user selection list 18 private System.Windows.Forms.ListBox displayListBox; [STAThread] 21 static void Main() 22 { 23 Application.Run( new CheckedListBoxTest() ); 24 } // item about to change, 27 // add or remove from displayListBox 28 private void inputCheckedListBox_ItemCheck( 29 object sender, 30 System.Windows.Forms.ItemCheckEventArgs e ) 31 { // public class ItemCheckEventArgs : EventArgs 32 // get reference of selected item 33 string item = 34 inputCheckedListBox.SelectedItem.ToString(); 35 CheckedListBoxListBoxItemCheck event handler

 2002 Prentice Hall. All rights reserved. Outline // if item checked add to listbox 37 // otherwise remove from listbox 38 if ( e.NewValue == CheckState.Checked )// check a new state 39 displayListBox.Items.Add( item ); // Items collection inherited 40 else// from ListBox 41 displayListBox.Items.Remove( item ); } // end method inputCheckedListBox_Click } // end class CheckedListBox System.Windows.Forms Namespace has public enum CheckState.Checked - specifies the state of a control, such as a check box, that can be checked, unchecked, or set to an indeterminate state.

Jozef Goetz contribution, ComboBox es Fig Demonstrating a ComboBox. Combine TextBox and drop-down list Add method adds object to collection Properties: DropDownStyle: determines type of ComboBox: Simple text is always visible and editable, doesn’t display a drop-down arrow button but has a scroll bar DropDown the default means that the text portion is editable but an arrow button must be clicked to see the list portion. DropDownList the text portion is not editable and the arrow button must be clicked to see the list portion.

Jozef Goetz contribution, ComboBoxes  ComboBox  Combines TextBox features with drop-down list  Drop-down list  Contains a list from which a value can be selected  Scrollbar appears if necessary Common Properties: Items: returns objects in the list SelectedItem: returns object selected SelectedIndex: returns index of selected item

Jozef Goetz contribution, ComboBox es  Represents a Windows combo box control.  For a list of all members of this type, see ComboBox Members.ComboBox Members  System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ListControl System.Windows.Forms.ComboBox System.ObjectSystem.MarshalByRefObjectSystem.ComponentModel.ComponentSystem.Windows.Forms.ControlSystem.Windows.Forms.ListControl

Jozef Goetz contribution, ComboBox es  Encapsulates a GDI+ drawing surface. This class cannot be inherited.  For a list of all members of this type, see Graphics Members.Graphics Members  System.Object System.MarshalByRefObject System.Drawing.Graphics System.ObjectSystem.MarshalByRefObject  Defines an object used to draw lines and curves. This class cannot be inherited.  For a list of all members of this type, see Pen Members.Pen Members  System.Object System.MarshalByRefObject System.Drawing.Pen System.ObjectSystem.MarshalByRefObject  Defines a brush of a single color. Brushes are used to fill graphics shapes, such as rectangles, ellipses, pies, polygons, and paths. This class cannot be inherited.  For a list of all members of this type, see SolidBrush Members.SolidBrush Members  System.Object System.MarshalByRefObject System.Drawing.Brush System.Drawing.SolidBrush System.ObjectSystem.MarshalByRefObjectSystem.Drawing.Brush

Jozef Goetz contribution, ComboBox es

 2002 Prentice Hall. All rights reserved. Outline 63 ComboBoxTest.cs 1 // Fig ed1 or ed4: ComboBoxTest.cs 2 // Using ComboBox to select shape to draw 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; public class ComboBoxTest : System.Windows.Forms.Form 12 { 13 // contains shape list (circle, square, ellipse, pie) 14 private System.Windows.Forms.ComboBox imageComboBox; [STAThread] 17 static void Main() 18 { 19 Application.Run( new ComboBoxTest() ); 20 } // get selected index, draw shape 23 private void imageComboBox_SelectedIndexChanged( 24 object sender, System.EventArgs e ) 25 { 26 // create graphics object, pen and brush 27 Graphics myGraphics = base.CreateGraphics(); // create Pen using color DarkRed 30 Pen myPen = new Pen( Color.DarkRed ); // create SolidBrush using color DarkRed 33 SolidBrush mySolidBrush = 34 new SolidBrush( Color.DarkRed ); 35 Create ComboBoxSelectedIndexChanged event handler Create graphics objectCreate penCreate brush

 2002 Prentice Hall. All rights reserved. Outline 64 ComboBoxTest.cs 36 // clear drawing area setting it to color White 37 myGraphics.Clear( Color.White ); // find index, draw proper shape 40 switch ( imageComboBox.SelectedIndex ) 41 { 42 case 0: // case circle is selected 43 myGraphics.DrawEllipse( 44 myPen, 50, 50, 150, 150 ); //x,y – center, width, high 45 break; // in this case circle 46 case 1: // case rectangle is selected 47 myGraphics.DrawRectangle( 48 myPen, 50, 50, 150, 150 ); //x,y – upper-left of //the rectangle, width, hight 49 break; 50 case 2: // case ellipse is selected 51 myGraphics.DrawEllipse( 52 myPen, 50, 85, 150, 115 ); //x,y – center, width, hight 53 break; 54 case 3: // case pie as a portion of an ellipse: 55 // x,y – upper-left of the rectangle, width, // high, the start angle (in degrees), the sweep angle of pie 55 myGraphics.DrawPie( 56 myPen, 50, 50, 150, 150, 0, 45 ); 57 break; 58 case 4: // case filled circle is selected 59 myGraphics.FillEllipse( 60 mySolidBrush, 50, 50, 150, 150 ); 61 break; 62 case 5: // case filled rectangle is selected 63 myGraphics.FillRectangle( 64 mySolidBrush, 50, 50, 150, 150 ); 65 break; 66 case 6: // case filled ellipse is selected 67 myGraphics.FillEllipse( 68 mySolidBrush, 50, 85, 150, 115 ); 69 break; Switch statement to determine correct object to draw Draw object

 2002 Prentice Hall. All rights reserved. Outline 65 ComboBoxTest.cs Program Output 70 case 7: // case filled pie is selected 71 myGraphics.FillPie( 72 mySolidBrush, 50, 50, 150, 150, 0, 45 ); 73 break; } // end switch } // end method imageComboBox_SelectedIndexChanged } // end class ComboBoxTest

 2002 Prentice Hall. All rights reserved. Outline 66 ComboBoxTest.cs Program Output

Jozef Goetz contribution, TreeView control Fig Displaying a sample tree in a TreeView. Click to expand node, displaying child nodes Root node Child nodes Click to collapse node, hiding child nodes Displays a hierarchical collection of labeled items, each represented by a TreeNode.TreeNode Folders of TreeView can be expanded or collapsed by clicking the + or – boxes that appear to their left Displays nodes hierarchically  Nodes  Objects that contain values –Parent node Contains child nodes Can be expanded or collapsed –Root node First parent node of a tree –Sibling nodes Have same parent node –Child nodes Can have child nodes of their own

Jozef Goetz contribution, TreeView s  Displays a hierarchical collection of labeled items, each represented by a TreeNode. TreeNode  For a list of all members of this type, see TreeView Members.TreeView Members  System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.TreeView System.ObjectSystem.MarshalByRefObjectSystem.ComponentModel.ComponentSystem.Windows.Forms.Control  Parent nodes have children  The first parent node is called the root  Use Add method to add nodes  The tree nodes in this collection are referred to as the root tree nodes.  Any tree node that is subsequently added to a root tree node is referred to as a child node.  A TreeNode represents a node of a TreeView.TreeView  For a list of all members of this type, see TreeNode Members.TreeNode Members  System.Object System.MarshalByRefObject System.Windows.Forms.TreeNode System.ObjectSystem.MarshalByRefObject  Each TreeNode has a Nodes collection which contains all the children of other TreeNodes objects assigned to the current TreeNode. Nodes  You can add, remove, or clone a TreeNode; –when doing so, all child tree nodes are added, removed, or cloned.  Each TreeNode can contain a collection of other TreeNode objects.

Jozef Goetz contribution, TreeNode.Nodes Property  Gets the collection of TreeNode objects assigned to the current tree node.TreeNode public TreeNodeCollection Nodes {get;}TreeNodeCollection  The Nodes property can hold a collection of other TreeNode objects.TreeNode  Each of the tree node in the collection has a Nodes property that can contain its own TreeNodeCollection. TreeNodeCollection  This nesting of tree nodes can make it difficult to navigate a tree structure.  The FullPath property makes it easier to determine your location in a tree.FullPath  TreeNodeCollection class represents a collection of TreeNode objects. TreeNodeCollectionTreeNode  System.Object System.Windows.Forms.TreeNodeCollection System.Object  Methods of TreeNodeCollection:TreeNodeCollection  Add –Adds a new tree node to the end of the current tree node collection with the specified label text : public virtual TreeNode Add(string);public virtual TreeNode (string); –Adds a previously created tree node to the end of the tree node collection: public virtual int Add (TreeNode);public virtual int  Remove –Removes the specified tree node from the tree node collection: public void Remove( TreeNode node );voidTreeNode  Remove At –Removes a tree node from the tree node collection at a specified index. public virtual void RemoveAt( int index );voidint

Jozef Goetz contribution, TreeView

Jozef Goetz contribution, TreeNode

Jozef Goetz contribution, TreeView Fig TreeNode Editor obtained after clicking on property Nodes Delete current node

 2002 Prentice Hall. All rights reserved. Outline 73 TreeViewDirector yStructureTest.c s 1 // Fig ed1: TreeViewDirectoryStructureTest.cs 2 // Using TreeView to display directory structure, use the load event 3 // it creates a tree for the entire C: drive 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; 10 using System.IO; public class TreeViewDirectoryStructureTest 13 : System.Windows.Forms.Form 14 { 15 // contains view of c: drive directory structure 16 private System.Windows.Forms.TreeView directoryTreeView; 17 // Dock property visually set to Fill 18 [STAThread] 19 static void Main() 20 { 21 Application.Run( 22 new TreeViewDirectoryStructureTest() ); 23 } public void PopulateTreeView( 26 string directoryValue, TreeNode parentNode ) ;//takes (name, root node) 27 { 28 // populate current node with subdirectories 29 string[] directoryArray = 30 Directory.GetDirectories( directoryValue );// System.IO namespace 31 // returns an array of subdirectories Class that creates children of root Get subdirectories of root

 2002 Prentice Hall. All rights reserved. Outline 74 TreeViewDirector yStructureTest.c s 32 // populate current node with subdirectories 33 try 34 { 35 if ( directoryArray.Length != 0 ) 36 { 37 // for every subdirectory, create new TreeNode, 38 // add as child of current node and recursively 39 // populate child nodes with subdirectories 40 foreach ( string directory in directoryArray ) // 1 st time is "C:\\", 41 { 42 // create TreeNode for current directory 43 TreeNode myNode = new TreeNode( directory ); // add current directory node to parent node 46 parentNode.Nodes.Add( myNode ); // recursively populate every subdirectory 49 PopulateTreeView( directory, myNode ); 50 } } // end if 53 } // catch exception 56 catch ( UnauthorizedAccessException ) 57 { 58 parentNode.Nodes.Add( "Access denied" ); // instead of displaying // the subdirectories 59 } } // end PopulateTreeView 62 Catches security exception Create new nodeRecursive call to finish tree

 2002 Prentice Hall. All rights reserved. Outline 75 TreeViewDirector yStructureTest.c s 63 // called by system when form loads 64 private void TreeViewDirectoryStructureTest_Load( 65 object sender, System.EventArgs e) 66 { 67 // add c:\ drive to directoryTreeView and 68 // insert its subfolders 69 directoryTreeView.Nodes.Add( "C:\\" ); 70 PopulateTreeView( 71 "C:\\", directoryTreeView.Nodes[ 0 ] ) ;//takes (name, root node’s index) 72 } } // end class TreeViewDirectoryStructure Create root

 2002 Prentice Hall. All rights reserved. Outline 76 TreeViewDirector yStructureTest.c s Program Output

Jozef Goetz contribution, Outline  TreeViewDirectory StructureForm.cs  (1 of 4) (a)(a) (b)(b)

Jozef Goetz contribution, Outline  TreeViewDirectoryStr uctureForm.cs  (2 of 4)

Jozef Goetz contribution, Outline  TreeViewDirectoryStr uctureForm.cs  (3 of 4) (a)(a) (b)(b)

Jozef Goetz contribution, Outline  TreeViewDirectoryStr uctureForm.cs  (4 of 4) (a) (b)

Jozef Goetz contribution, ListViews  ListView Control  Similar to ListBox  View and select from multiple items  Select multiple items at same time  Displays icons along side of list items

Jozef Goetz contribution, ListView s similar to ListBox  Represents a Windows list view control, which displays a collection of items that can be displayed using 1 of 4 different views  as large icons, as small icons, or as small icons in a vertical list.  For a list of all members of this type, see ListView Members.ListView Members  System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ListView System.ObjectSystem.MarshalByRefObjectSystem.ComponentModel.ComponentSystem.Windows.Forms.Control  Displays list of items  Can select one or more items from list  Displays icons to go along with items  A ListView control allows you to display a list of items with item text and, optionally, an icon to identify the type of item.  For example, the Windows Explorer list of files is similar in appearance to a ListView control.  It displays a list of the files and folders currently selected in the tree.  Each file and folder displays an icon associated with it to help identify the type of file or folder.

Jozef Goetz contribution, ListView.Items Property  public ListView.ListViewItemCollection Items {get;}ListView.ListViewItemCollection  Using the ListView.ListViewItemCollection returned by this property, you can add items, remove items, and obtain a count of itemsListView.ListViewItemCollection  System.Object System.Windows.Forms.ListView.ListViewItemCollection System.Object  this class represents the collection of items and stores them in a ListView control.ListView  public class ListView.ListViewItemCollection : IList, ICollection, IEnumerable  Methods of ListView.ListViewItemCollection: ListView.ListViewItemCollection  Add - Adds an item to the collection of items Add  where: public virtual ListViewItem Add( ListViewItem value );ListViewItem  Insert -Inserts an item into the collection at the specified index Insert  where: public ListViewItem Insert( int index, ListViewItem item );ListViewItemintListViewItem  Remove removes the specified item from the collection. Remove  where: public virtual void Remove( ListViewItem item );voidListViewItem

Jozef Goetz contribution, ListViewItem class  The ListViewItem class defines the appearance, behavior, and data associated with an item that is displayed in the ListView control.  ListViewItem objects System.Object System.Windows.Forms.ListViewItem System.Object  can be displayed in the ListView control in 1 of 4 different views.  LargeIcon (large icon displayed, items can be in multiple columns),  Small­Icon (small icon displayed),  List (small icons displayed, items appear in a single column) and  Details (like List, but multiple columns of information can be displayed per item).  Items can also have subitems that contain information that is related to the parent item.  The 4 view style, details view, allows you to display the item and its subitems in a grid with column headers that can be used to identify the information being displayed in a subitem.

Jozef Goetz contribution, DirectoryInfo class  Exposes instance methods for creating, moving, and enumerating through directories and subdirectories.  For a list of all members of this type, see DirectoryInfo Members. DirectoryInfo Members  System.Object System.MarshalByRefObject System.IO.FileSystemInfo System.IO.DirectoryInfo System.ObjectSystem.MarshalByRefObjectSystem.IO.FileSystemInfo

Jozef Goetz contribution, FileInfo class  Provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects.FileStream  For a list of all members of this type, see FileInfo Members.FileInfo Members  System.Object System.MarshalByRefObject System.IO.FileSystemInfo System.IO.FileInfo System.ObjectSystem.MarshalByRefObjectSystem.IO.FileSystemInfo

Jozef Goetz contribution, ListView s

Jozef Goetz contribution, ListView s Fig Image Collection Editor window for an ImageList component. It can be dragged from the ToolBox.

 2002 Prentice Hall. All rights reserved. Outline 89 ListViewTest.cs 1 // Fig ed1 or ed3, (ed4): ListViewTest.cs 2 // Displaying directories and their contents in ListView. 3 // it scans the contents of the directory as it browses 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; 10 using System.IO; public class ListViewTest : System.Windows.Forms.Form 13 { 14 // display labels for current location 15 // in directory tree 16 private System.Windows.Forms.Label currentLabel; 17 private System.Windows.Forms.Label displayLabel; //currentDirectory // display contents of current directory 20 private System.Windows.Forms.ListView browserListView; // specifies images for file icons and folder icons 23 private System.Windows.Forms.ImageList fileFolder; // get current directory 26 string currentDirectory = 27 Directory.GetCurrentDirectory(); [STAThread] 30 static void Main() 31 { 32 Application.Run( new ListViewTest() ); 33 } 34 Create Image ListLoad the current directory (a)

 2002 Prentice Hall. All rights reserved. Outline 90 ListViewTest.cs 35 // browse directory user clicked or go up one level 36 private void browserListView_Click( 37 object sender, System.EventArgs e ) 38 { 39 // ensure item selected 40 if ( browserListView.SelectedItems.Count != 0 ) 41 { 42 // if first item selected, go up one level 43 if ( browserListView.Items[ 0 ].Selected ) 44 { 45 // create DirectoryInfo object for directory 46 DirectoryInfo directoryObject = 47 new DirectoryInfo( currentDirectory ); // if directory has parent, load it 50 if ( directoryObject.Parent != null ) //test property Parent 51 LoadFilesInDirectory( 52 directoryObject.Parent.FullName ); 53 } // selected directory or file is not as the 1 st item 56 else 57 { 58 // directory or file chosen 59 string chosen = 60 browserListView.SelectedItems[ 0 ].Text; //gives the text // of the selected item (1 st item in the collection) // if item selected is directory 63 if ( Directory.Exists( currentDirectory + 64 "\\" + chosen ) ) 65 { Test to see if at rootReturn parent of current directory Check if selected item is directory Test if item is selected If first item selected go up one level Make directory information

 2002 Prentice Hall. All rights reserved. Outline 91 ListViewTest.cs 66 // load subdirectory 67 // if in c:\, do not need '\', 68 // otherwise we do 69 if ( currentDirectory == "C:\\" ) 70 LoadFilesInDirectory( 71 currentDirectory + chosen ); // has “//” already 72 else 73 LoadFilesInDirectory( 74 currentDirectory + "\\" + chosen ); 75 } //end if } // end else // update displayLabel 80 displayLabel.Text = currentDirectory; } // end if } // end method browserListView_Click // display files/subdirectories of current directory 87 public void LoadFilesInDirectory( 88 string currentDirectoryValue ) 89 { 90 // load directory information and display 91 try 92 { 93 // clear ListView and set first item 94 browserListView.Items.Clear(); 95 browserListView.Items.Add( "Go Up One Level" ); // 1 st item to display 96 Class to load files in current directory Update to display current directory Load subdirectory (a)(a)

 2002 Prentice Hall. All rights reserved. Outline 92 ListViewTest.cs 97 // update current directory 98 currentDirectory = currentDirectoryValue; 99 DirectoryInfo newCurrentDirectory = // if no permission, an exception is thrown 100 new DirectoryInfo( currentDirectory ); //System.IO namespace // put files and directories into arrays 103 DirectoryInfo[] directoryArray = 104 newCurrentDirectory.GetDirectories(); FileInfo[] fileArray = 107 newCurrentDirectory.GetFiles(); // add directory names to ListView 110 foreach ( DirectoryInfo dir in directoryArray ) 111 { 112 // add directory to ListView 113 ListViewItem newDirectoryItem = 114 browserListView.Items.Add( dir.Name ); // set directory image 117 newDirectoryItem.ImageIndex = 0; //this value 0 was setup via line 153 // in the ImageList // Collection Editor – also see a few slides back 118 } // Fig // add file names to ListView 121 foreach ( FileInfo file in fileArray ) 122 { 123 // add file to ListView 124 ListViewItem newFileItem = 125 browserListView.Items.Add( file.Name ); newFileItem.ImageIndex = 1; //this value 0 was setup via line 154 // in the ImageList // Collection Editor – also see a few slides back 128 } // Fig } // end try 130 Get subdirectories of current directory, different than a former program Get files of current directory Add directory to list Add file to list

 2002 Prentice Hall. All rights reserved. Outline // access denied 132 catch ( UnauthorizedAccessException exception ) 133 { 134 MessageBox.Show( 135 "Warning: Some fields may not be " "visible due to permission settings", 137 "Attention", 0, MessageBoxIcon.Warning ); 138 } } // end method LoadFilesInDirectory // handle load event when Form displayed for first time 143 private void ListViewTest_Load( 144 object sender, System.EventArgs e ) 145 { 146 // set image list 147 Image folderImage = Image.FromFile( 148 currentDirectory + "\\images\\folder.bmp" ); Image fileImage = Image.FromFile( currentDirectory "\\images\\file.bmp" ); 152 // add to ImageList control 153 fileFolder.Images.Add( folderImage ); 154 fileFolder.Images.Add( fileImage ); // load current directory into browserListView control 157 LoadFilesInDirectory( currentDirectory ); 158 displayLabel.Text = currentDirectory; } // end method ListViewTest_Load } // end class ListViewTest Security exception handler Load Images (a )

 2002 Prentice Hall. All rights reserved. Outline 94 ListViewTest.cs Program Output (b) (c) (a)

Jozef Goetz contribution, Software Engineering Observation 15.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.

Jozef Goetz contribution, TabControl  Creates tabbed windows  to fit a large # of controls and group them  similar to Panels and GroupBoxes  Saves space using TabPage objects  Windows called TabPage objects  TabPages can contain controls  TabPages have own Click event for when tab is clicked TabPage TabControl Controls in TabPage

Jozef Goetz contribution, Tab Control s Fig. Tabbed pages in Visual Studio.NET. Tab pages

Jozef Goetz contribution, Tab Control s Fig Adding TabPage s to the TabControl First the TabControl was dragged and dropped onto a form in design mode.

Jozef Goetz contribution, Tab Control s

 2002 Prentice Hall. All rights reserved. Outline 100 UsingTabs.cs 1 // Fig : UsingTabs.cs 2 // Using TabControl to display various font settings. 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; public class UsingTabs : System.Windows.Forms.Form 12 { 13 // output label reflects text changes 14 private System.Windows.Forms.Label displayLabel; // table control containing table pages colorTabPage, 17 // sizeTabPage, messageTabPage and aboutTabPage 18 private System.Windows.Forms.TabControl 19 optionsTabControl; // table page containing color options 22 private System.Windows.Forms.TabPage colorTabPage; 23 private System.Windows.Forms.RadioButton 24 greenRadioButton; 25 private System.Windows.Forms.RadioButton redRadioButton; 26 private System.Windows.Forms.RadioButton 27 blackRadioButton; 28 Color tab Color buttons for color tab

 2002 Prentice Hall. All rights reserved. Outline 101 UsingTabs.cs 29 // table page containing font size options 30 private System.Windows.Forms.TabPage sizeTabPage; 31 private System.Windows.Forms.RadioButton 32 size20RadioButton; 33 private System.Windows.Forms.RadioButton 34 size16RadioButton; 35 private System.Windows.Forms.RadioButton 36 size12RadioButton; // table page containing text display options 39 private System.Windows.Forms.TabPage messageTabPage; 40 private System.Windows.Forms.RadioButton 41 goodByeRadioButton; 42 private System.Windows.Forms.RadioButton 43 helloRadioButton; // table page containing about message 46 private System.Windows.Forms.TabPage aboutTabPage; 47 private System.Windows.Forms.Label messageLabel; [STAThread] 50 static void Main() 51 { 52 Application.Run( new UsingTabs() ); 53 } // event handler for black color radio button 56 private void blackRadioButton_CheckedChanged( 57 object sender, System.EventArgs e ) 58 { 59 displayLabel.ForeColor = Color.Black; 60 } 61 Size tab Size buttons Message tabAbout tabEvent handler

 2002 Prentice Hall. All rights reserved. Outline 102 UsingTabs.cs 62 // event handler for red color radio button 63 private void redRadioButton_CheckedChanged( 64 object sender, System.EventArgs e ) 65 { 66 displayLabel.ForeColor = Color.Red; 67 } // event handler for green color radio button 70 private void greenRadioButton_CheckedChanged( 71 object sender, System.EventArgs e ) 72 { 73 displayLabel.ForeColor = Color.Green; 74 } // event handler for size 12 radio button 77 private void size12RadioButton_CheckedChanged( 78 object sender, System.EventArgs e ) 79 { 80 displayLabel.Font = 81 new Font( displayLabel.Font.Name, 12 ); 82 } // event handler for size 16 radio button 85 private void size16RadioButton_CheckedChanged( 86 object sender, System.EventArgs e ) 87 { 88 displayLabel.Font = 89 new Font( displayLabel.Font.Name, 16 ); 90 } 91 Event handlers

 2002 Prentice Hall. All rights reserved. Outline 103 UsingTabs.cs 92 // event handler for size 20 radio button 93 private void size20RadioButton_CheckedChanged( 94 object sender, System.EventArgs e ) 95 { 96 displayLabel.Font = 97 new Font( displayLabel.Font.Name, 20 ); 98 } // event handler for message "Hello!" radio button 101 private void helloRadioButton_CheckedChanged( 102 object sender, System.EventArgs e ) 103 { 104 displayLabel.Text = "Hello!"; 105 } // event handler for message "Goodbye!" radio button 108 private void goodByeRadioButton_CheckedChanged( 109 object sender, System.EventArgs e ) 110 { 111 displayLabel.Text = "Goodbye!"; 112 } } // end class UsingTabs Event handlers

 2002 Prentice Hall. All rights reserved. Outline 104 UsingTabs.cs Program Output

Jozef Goetz contribution, Software Engineering Observation 15.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.

Jozef Goetz contribution, Multiple Document Interface (MDI) Windows  MDI  Allows multiple windows  Parent window –Application window –Can have many child windows  Child window –Cannot be parent –Has exactly one parent –Cannot be moved outside parent –Functionality can be different than other child windows from same parent

Jozef Goetz contribution, Multiple Document Interface (MDI) Windows Fig MDI parent and MDI child. MDI parent MDI child

Jozef Goetz contribution, Multiple Document Interface (MDI) Windows Fig SDI and MDI forms. Single Document Interface (SDI)Multiple Document Interface (MDI)

Jozef Goetz contribution, Multiple-Document Interface (MDI) Windows  Users can edit multiple documents at once  Usually more complex then single-document-interface (SDI) applications  SDI apps have been created so far.  The application window of an MDI program is called parent, and each window inside the app is referred to as a child window  A max of 1 child (window) w. can be actived at once  A child w. cannot be parents themselves and cannot be moved outside their parent  A child’s functionality can be different from the functionality of others child windows of the parent  E.g. one child might edit images,  another – edit text or display network traffic

Jozef Goetz contribution, Multiple-Document Interface (MDI) Windows  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 (c) TileHorizontal (a) ArrangeIcons (b) Cascade (d) Tilevertical

Jozef Goetz contribution, 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.

Jozef Goetz contribution, Multiple Document Interface (MDI) Windows

Jozef Goetz contribution, 2012  Right click the project in the Solution Explorer, select Project > Add Windows Form… and name the file.  Set the Form ’s MdiParent property to the parent Form and call the child Form ’s Show method. ChildFormClass childForm = New ChildFormClass (); childForm.MdiParent = parentForm; childForm.Show();  In most cases, the parent Form creates the child, so the parentForm reference is this Multiple Document Interface (MDI) Windows (Cont.)

Jozef Goetz contribution, The list of open child windows Fig MenuStrip property MdiWindowListItem example is setup as windowToolStripMenuItem Separator bar and child windows 9 or more child windows enables the More Windows... option Child windows list  Property MdiWindowListItem of class MenuStrip specifies which menu, if any, displays a list of open child windows.

Jozef Goetz contribution, 2012 The list of open child windows © by Pearson Education, Inc. All Rights Reserved.

Jozef Goetz contribution, Fig | MdiLayout enumeration values. (c) TileHorizontal (a) ArrangeIcons (b) Cascade (d) Tilevertical

Jozef Goetz contribution, Outline UsingMDIForm.cs ( 1 of 6 ) Class UsingMDIForm (Fig ) demonstrates MDI windows. Fig | MDI parent-window class. (Part 1 of 6.)

Jozef Goetz contribution, UsingMDIForm.cs ( 2 of 6 ) Fig | MDI parent-window class. (Part 2 of 6.) Adding a new child Form with certain properties. See next slides. Adding a new child Form with certain properties.

Jozef Goetz contribution, Outline UsingMDIForm.cs ( 3 of 6 ) Fig | MDI parent-window class. (Part 3 of 6.) Adding a new child Form with certain properties.

Jozef Goetz contribution, Outline UsingMDIForm.cs ( 4 of 6 ) Fig | MDI parent-window class. (Part 4 of 6.) Setting the layout of child Form s.  MDI containers allow you to organize the placement of its child windows.  Method LayoutMdi takes a value of the MdiLayout enumeration

Jozef Goetz contribution, 2012 Fig | MDI parent-window class. (Part 5, 6 of 6.) a) Creating a child windowb) Viewing the child window c) Changing child window organizationd) Child windows in Cascade view

Jozef Goetz contribution, Outline ChildForm.cs ( 1 of 2 ) Define the MDI child class by right clicking the project in the Solution Explorer and selecting Add > Windows Form…. Name the new class ChildForm (Fig ). Fig | MDI child ChildForm. (Part 1 of 2.)

Jozef Goetz contribution, Outline ChildForm.cs ( 2 of 2 ) Fig | MDI child ChildForm. (Part 2 of 2.) Setting the title-bar text. Retrieving the specified image resource and displaying it.

Jozef Goetz contribution, Visual Inheritance  Create Form by inheriting from another Form  Derived Form inherits functionality of base Form  Derived Form inherits visual aspects  size,  color,  background etc.  of base Form

Jozef Goetz contribution, Outline  VisualInhe ritanceFor m.cs  Right click the project name in the Solution­ Explorer and select Properties, then choose the Application tab.  In the Output type drop-down list, change Windows Application to Class Library.  Building the project produces the.dll.

Jozef Goetz contribution, Outline  VisualInheritance TestForm.cs  (1 of 2) Derived class cannot modify these controls. Derived class can modify this control.

Jozef Goetz contribution, 2012 Derived class cannot modify these controls. Derived class can modify this control.

Jozef Goetz contribution, 2012  The.NET Framework allows you to create custom controls.  Custom controls appear in the user’s Toolbox.  There are multiple ways to create a custom control, depending on the level of customization that you want User-Defined Controls © by Pearson Education, Inc. All Rights Reserved.

Jozef Goetz contribution, User-Defined Controls 2. User-defined control can inherit from class Control and Component System.Object System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ScrollableControl System.Windows.Forms.ContainerControl System.Windows.Forms.UserControlSystem.MarshalByRefObjectSystem.ComponentModel.ComponentSystem.Windows.Forms.ScrollableControlSystem.Windows.Forms.ContainerControl System.Object System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control 1. Custom Control is a base class for the User Control classesSystem.MarshalByRefObjectSystem.ComponentModel.Component Ex: If existing control is a label. User Control class can change appearance of a label by inheriting from class label by overriding method OnPaint.

Jozef Goetz contribution, User-Defined Controls  We will implement a UserControl composed of a label and a timer – whenever the timer generates an event, the label is updated to reflect the current time  Timers are invisible components that reside on a form and generate Tick events at a set interval (it is set by the Interval property) System.Object System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.TimerSystem.MarshalByRefObjectSystem.ComponentModel.Component For a list of all members of this type, see Timer Members.Timer Members

Jozef Goetz contribution, 2012  Timer s are non-visual components that generate Tick events at a set interval.  The Timer ’s Interval property defines the number of milliseconds between events.  Create a UserControl class for the project by selecting Project > Add User Control ….  We name the file (and the class) ClockUserControl.  Add a Label and a Timer to the UserControl.  Set the Timer interval to 1000 milliseconds.  clockTimer must be enabled by setting Enabled to true.  Drag it the user control to the Form and run the app. p.621 – 2 nd last paragraph User-Defined Controls (Cont.)

 2002 Prentice Hall. All rights reserved. Outline 132 ClockUserControl.cs 1 // Fig : ClockUserControl.cs 2 // User-defined control with a timer and a label. 3 4 using System; 5 using System.Collections; 6 using System.ComponentModel; 7 using System.Drawing; 8 using System.Data; 9 using System.Windows.Forms; public class ClockUserControl 12 : System.Windows.Forms.UserControl 13 { 14 private System.Windows.Forms.Timer clockTimer; 15 private System.Windows.Forms.Label displayLabel; // update label at every tick 18 private void clockTimer_Tick( 19 object sender, System.EventArgs e ) 20 { 21 // get current time (Now), convert to string 22 displayLabel.Text = DateTime.Now.ToLongTimeString(); } // end method clockTimer_Tick } // end class ClockUserControl TimerLabelUpdate label methodDisplay current time

Jozef Goetz contribution, User-Defined Controls

Jozef Goetz contribution, User-Defined Controls Fig. Custom-control creation. – to create it see p.621 bottom

Jozef Goetz contribution, User-Defined Controls (Cont.)  Create a new Windows application.  Right click the ToolBox and select Choose Items….  In the Choose Toolbox Items dialog, click Browse…  Select the. dll file that you created.  The item will then appear in the Choose Toolbox Items dialog (Fig ).  Check this item and click OK to add the item to the Toolbox.

Jozef Goetz contribution, User-Defined Controls Fig. Custom control added to a Form. New Toolbox icon Newly inserted control