136
Jozef Goetz contribution, 1 1 Pearson Education, Inc. All rights reserved. 2002 Prentice Hall. All rights reserved.

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

Embed Size (px)

Citation preview

Chapter 12 - XSL: Extensible Stylesheet Language Transformations 2002 Prentice Hall. All rights reserved.
*
*
I claim not to have controlled events, but confess plainly that events have controlled me.
Abraham Lincoln
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
It is the east, and Juliet is
the sun!
William Shakespeare
Outline
15.13 Visual Inheritance
15.14 User-Defined Controls
Chapter 15: Graphical User Interface Concepts: Part 2: Objectives
To be able to create menus, window tabs and multiple-document-interface (MDI) programs.
To understand the use of the ListView and TreeView controls for displaying information.
To be able to use hyperlinks with the LinkLabel control.
To be able to display lists using ListBoxes and ComboBoxes.
To create custom controls.
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
Menus organize commands without “cluttering” the GUI.
Fig. 15.1 | Menus, submenus and menu items.
15.2 Menus
*
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. 15.2 | Editing menus in Visual Studio.
MenuStrip icon
Main menu bar
*
After you press the Enter key, the menu item is added.
More Type Here TextBoxes allow you to add more items (Fig. 15.3).
Fig. 15.3 | Adding ToolStripMenuItems to a MenuStrip.
15.2 Menus
Place & character
character can be
TextBoxes for
*
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.
15.2 Menus
*
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. 15.4 | Setting a menu item’s shortcut keys.
Select key (modifier and key
combination specifies the
Setting modifier keys
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 item options
Visual Studio allows you to add TextBoxes and ComboBoxes 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).
15.2 Menus
Setting modifier keys
*
Menu item options
and an event. (Part 1 of 2.)
*
Description
HasChildren
RightToLeft
Causes text to display from right to left. This is useful for languages that are read from right to left.
ToolStripMenuItem Properties
Checked
Indicates whether a menu item is checked. The default value is false, meaning that the menu item is unchecked.
CheckOnClick
Indicates that a menu item should appear checked or unchecked as the item is clicked.
Index
Specifies an item’s position in its parent menu. A value of 0 places the MenuItem at the beginning of the menu.
MenuItems
Jozef Goetz contribution, 2012
and an event. (Part 2 of 2.)
*
Description
ShortcutKeyDisplayString
Specifies text that should appear beside a menu item for a shortcut key. If left blank, the key names are displayed. Otherwise, the text in this property is displayed for the shortcut key.
ShortcutKeys
Specifies the shortcut key for the menu item (e.g., <Ctrl>-F9 is equivalent to clicking a specific item).
ShowShortcutKeys
Indicates whether a shortcut key is shown beside menu item text. The default is true, which displays the shortcut key.
Text
Specifies the menu item’s text. To create an Alt access shortcut, precede a character with & (e.g., &File to specify a menu named File with the letter F underlined).
Common ToolStripMenuItem Event
Click
Generated when an item is clicked or a shortcut key is used. This is the default event when the menu is double clicked in the designer.
Jozef Goetz contribution, 2012
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...).
*
2 // Using Menus to change font colors and styles.
3 using System;
4 using System.Drawing;
5 using System.Windows.Forms;
6
7 // our Form contains a Menu that changes the font color
8 // and style of the text displayed in Label
9 public partial class MenuTestForm : Form
10 {
19 {
22 "About", MessageBoxButtons.OK, MessageBoxIcon.Information );
23 } // end method aboutToolStripMenuItem_Click
27 {
32 private void ClearColor()
43 {
45 ClearColor();
48 displayLabel.ForeColor = Color.Black;
49 blackToolStripMenuItem.Checked = true;
54 {
56 ClearColor();
59 displayLabel.ForeColor = Color.Blue;
60 blueToolStripMenuItem.Checked = true;
65 {
67 ClearColor();
70 displayLabel.ForeColor = Color.Red;
71 redToolStripMenuItem.Checked = true;
76 {
78 ClearColor();
81 displayLabel.ForeColor = Color.Green;
82 greenToolStripMenuItem.Checked = true;
86 private void ClearFont()
93
94 // update Menu state and set Font to Times New Roman
95 private void timesToolStripMenuItem_Click( object sender, EventArgs e )
96 {
98 ClearFont();
101 timesToolStripMenuItem.Checked = true;
104 } // end method timesToolStripMenuItem_Click
107 private void courierToolStripMenuItem_Click(
109 {
111 ClearFont();
118
119 // update Menu state and set Font to Comic Sans MS
120 private void comicToolStripMenuItem_Click( object sender, EventArgs e )
121 {
123 ClearFont();
126 comicToolStripMenuItem.Checked = true;
129 } // end method comicToolStripMenuItem_Click
132 private void boldToolStripMenuItem_Click( object sender, EventArgs e )
133 {
136
137 // use logical exlusive OR to toggle bold, keep all other styles
138 displayLabel.Font = new Font(
144 private void italicToolStripMenuItem_Click(
146 {
149
150 // use logical exclusive OR to toggle italic, keep all other styles
151 displayLabel.Font = new Font(
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.
15.2  Menus
*
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. 15.8 | MonthCalendar control.
Current day is outlined
Selected day is highlighted
Fig. 15.8 | MonthCalendar control.
*
Description
FirstDayOfWeek
Sets which day of the week is the first displayed for each week in the calendar.
MaxDate
MaxSelectionCount
The maximum number of dates that can be selected at once.
MinDate
MonthlyBoldedDates
An array of dates that will displayed in bold in the calendar.
SelectionEnd
SelectionRange
SelectionStart
Common MonthCalendar Event
Jozef Goetz contribution, 2012
*
Fig. 15.10 | DateTimePicker properties and an event. (Part 1 of 2.)
The DateTimePicker control displays a calendar when a down arrow is selected.
*
Description
CalendarMonthBackground
CustomFormat
Sets the custom format string for the user’s options.
Format
Sets the format of the date and/or time used for the user’s options.
MaxDate
MinDate
ShowCheckBox
Indicates if a CheckBox should be displayed to the left of the selected date and time.
Jozef Goetz contribution, 2012
*
*
Description
ShowUpDown
Used to indicate that the control should have up and down Buttons. This is helpful for instances when the DateTimePicker is used to select a time—the Buttons can be used to increase or decrease hour, minute and second values.
Value
Common DateTimePicker Event
ValueChanged
Generated when the Value property changes, including when the user selects a new date or time.
Jozef Goetz contribution, 2012
Outline
DateTimePickerForm.cs
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.
(c)
(d)
1 // Fig. 15.11: DateTimePickerForm.cs
2 // Using a DateTimePicker to select a drop off time and then an estimated //delivery date displayed (for online DVD rental)
3 using System;
4 using System.Windows.Forms;
7 {
16 {
18
19 // add extra time when items are dropped off around Sunday
20 if ( dropOffDate.DayOfWeek == DayOfWeek.Friday ||
25 outputLabel.Text = dropOffDate.AddDays( 3 ).ToLongDateString();
26 else
28 outputLabel.Text = dropOffDate.AddDays( 2 ).ToLongDateString();
29 } // end method dateTimePickerDropOff_ValueChanged
Jozef Goetz contribution, 2012
a) Clicking the down arrow
b) Selecting a day from the calendar
c) The Label updates
d) Selecting another day
*
32 {
34 dateTimePickerDropOff.MinDate = DateTime.Today;
37 dateTimePickerDropOff.MaxDate = DateTime.Today.AddYears( 1 );
38 } // end method DateTimePickerForm_Load
39 } // end class DateTimePickerForm
Jozef Goetz contribution, 2012
Files
Can change color
15.5 LinkLabels
Fig. 15.5 LinkLabel control in the design phase and in running program.
LinkLabel on a form
*
*
The LinkLabel control displays links to other resources, such as files or web pages (Fig. 15.12).
Fig. 15.12 | 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
Represents a Windows label control that can display hyperlinks.
For a list of all members of this type, see LinkLabel Members .
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
*
Common Properties
ActiveLinkColor
Specifies the color of the active link when clicked. Default is red.
LinkArea
Specifies which portion of text in the LinkLabel is treated as part of the link.
LinkBehavior
Specifies the link’s behavior, such as how the link appears when the mouse is placed over it.
LinkColor
Specifies the original color of all links before they have been visited. Default is blue.
Links
Lists the LinkLabel.Link objects, which are the links contained in the LinkLabel.
LinkVisited
If True, link appears as if it were visited (its color is changed to that specified by property VisitedLinkColor). Default False.
Text
UseMnemonic
If True, & character in Text property acts as a shortcut (similar to the Alt shortcut in menus).
VisitedLinkColor
Common Event
LinkClicked
Generated when link is clicked. Default when control is double-clicked in designer.
Fig. 13.6 LinkLabel properties and events.
2002 Prentice Hall. All rights reserved.
Outline
2 // Using LinkLabels to create hyperlinks.
3
12 {
14 private System.Windows.Forms.LinkLabel driveLinkLabel;
15 private System.Windows.Forms.LinkLabel deitelLinkLabel;
16 private System.Windows.Forms.LinkLabel notepadLinkLabel;
26 System.Windows.Forms.LinkLabelLinkClickedEventArgs e )
System.Diagnostics.Process.Start( "C:\\" ); //Start( @”C:\”) in ed4
@ indicates that all characters in the string should be interprated literally – this is known as a verbatim string
30 }
31
*
Outline
34 System.Windows.Forms.LinkLabelLinkClickedEventArgs e )
39 }
40
50 System.Diagnostics.Process.Start( "notepad" );
System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Diagnostics.Process
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.
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.
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.
Deitel website
event handler
a web page and an application. (Part 4 of 6.)
Click first LinkLabel to
LinkLabelTest
Form.cs
a web page and an application. (Part 5 of 6.)
Click second LinkLabel to go to Deitel website
LinkLabelTest
Form.cs
a web page and an application. (Part 6 of 6.)
Click on third LinkLabel
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
ListBox
*
ListBoxes
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 .
Items
Returns lists the collection of all items within the ListBox.
This property enables you to obtain a reference to the list of items currently stored in the ListBox .
With this reference, you can add items, remove items, and obtain a count of the items in the collection
public ListBox.ObjectCollection Items {get;} // returns a class object
MultiColumn
Indicates whether the ListBox can break a list into multiple columns. Multiple columns are used to make vertical scroll bars unnecessary.
SelectedIndex
Returns the index of the currently selected item. If the user selects multiple items, this method arbitrarily returns one of the selected indices; if no items have been selected, the method returns -1.
SelectedIndices
Returns a collection of the indices of all currently selected items.
SelectedItem
Returns a reference to the currently selected item (if multiple items are selected, it returns the item with the lowest index number).
SelectedItems
SelectionMode
Determines the number of items that can be selected and the means through which multiple items can be selected. Values None, One, MultiSimple (multiple selection allowed) and MultiExtended (multiple selection allowed via a combination of arrow keys, mouse clicks and Shift and Control buttons).
Sorted
GetSelected
Takes an index, and returns True if the corresponding item is selected.
Common Event
SelectedIndexChanged
Generated when selected index changes. Default when control is double-clicked in designer.
Fig. 13.9 ListBox properties, methods and events.
Jozef Goetz contribution, 2012
*
*
Description
GetSelected
Takes an index as an argument, and returns true if the corresponding item is selected.
Common Event
SelectedIndexChanged
Generated when the selected index changes. This is the default event when the control is double clicked in the designer.
Jozef Goetz contribution, 2012
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
*
Outline
2 // Program to add, remove and clear list box items.
3
12 {
15 private System.Windows.Forms.ListBox displayListBox;
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;
Allows users to add and remove items from ListBox
Uses event handlers to add to, remove from and clear list
Display ListBox
Outline
32 // and clear input box
33 private void addButton_Click(
35 {
41 private void removeButton_Click(
43 {
45 if ( displayListBox.SelectedIndex != -1 )
53 {
60 {
Exit
Outline
15.7 CheckedListBoxes
Displays a ListBox in which a check box is displayed to the left of each item.
For a list of all members of this type, see CheckedListBox Members .
Can add to, remove from or clear list
Can select multiple items from the list
Properties CurrentValue and NewValue return state of object selected
*
Common Properties
(All the ListBox properties and events are inherited by CheckedListBox.)
CheckedItems
The collection of items that are checked. Not the same as the selected items, which are highlighted (but not necessarily checked).
CheckedIndices
Returns indices for the items that are checked. Not the same as the selected indices.
SelectionMode
Can only have values One (allows multiple selection) or None (does not allow multiple selection).
Common Methods
Takes an index and returns true if corresponding item checked.
Common Events
ItemCheck
ItemCheckEventArgs Properties:
Whether current item is checked or unchecked. Values Checked, Unchecked or Indeterminate.
Index
NewValue
New state of item – see line 38 in the program
Fig. 15.19 CheckedListBox properties, methods and events.
Jozef Goetz contribution, 2012
System.Windows.Forms Namespace has
public enum CheckState.Checked
*
Outline
1 // Fig. 13.13 ed1 or 15.20 ed3: CheckedListBoxTest.cs
2 // Using the checked list boxes to add items to a list box
3
12 {
14 private System.Windows.Forms.CheckedListBox
27 // add or remove from displayListBox
28 private void inputCheckedListBox_ItemCheck(
32 // get reference of selected item
33 string item =
Outline
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
System.Windows.Forms Namespace has
public enum CheckState.Checked
*
Add method adds object to collection
Properties:
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
*
Drop-down list
Contains a list from which a value can be selected
Scrollbar appears if necessary
SelectedItem: returns object selected
*
Represents a Windows combo box control.
For a list of all members of this type, see ComboBox Members .
Encapsulates a GDI+ drawing surface. This class cannot be inherited.
For a list of all members of this type, see Graphics Members .
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 .
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 .
Common Properties
Determines the type of combo box.
· Value Simple means that the text portion is editable and the list portion is always visible.
· Value DropDown (the default) means that the text portion is editable but an arrow button must be clicked to see the list portion.
· Value DropDownList means that the text portion is not editable and the arrow button must be clicked to see the list portion.
Items
MaxDropDownItems
Maximum number of items to display in the drop-down list (between 1 and 100). If value is exceeded, a scroll bar appears.
SelectedIndex
Returns index of currently selected item. If there is no currently selected item, -1 is returned.
SelectedItem
Sorted
Common Events
SelectedIndexChanged
Similar to ListBox
Raised when selected index changes (i.e., a check box has been checked or unchecked). Default when control double-clicked in designer.
Fig. 13.15 ComboBox properties and events.
2002 Prentice Hall. All rights reserved.
Outline
3
12 {
14 private System.Windows.Forms.ComboBox imageComboBox;
23 private void imageComboBox_SelectedIndexChanged(
25 {
27 Graphics myGraphics = base.CreateGraphics();
31
33 SolidBrush mySolidBrush =
Outline
37 myGraphics.Clear( Color.White );
40 switch ( imageComboBox.SelectedIndex )
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(
//the rectangle, width, hight
51 myGraphics.DrawEllipse(
52 myPen, 50, 85, 150, 115 ); //x,y – center, width, hight
53 break;
case 3: // case pie as a portion of an ellipse:
// x,y – upper-left of the rectangle, width,
// high, the start angle (in degrees), the sweep angle of pie
55 myGraphics.DrawPie(
57 break;
59 myGraphics.FillEllipse(
61 break;
63 myGraphics.FillRectangle(
65 break;
67 myGraphics.FillEllipse(
69 break;
Draw object
Outline
71 myGraphics.FillPie(
73 break;
Outline
Fig. 15.24 Displaying a sample tree in a TreeView.
Displays a hierarchical collection of labeled items, each represented by a TreeNode .
Folders of TreeView can be expanded or collapsed by clicking the + or – boxes that appear to their left
Displays nodes hierarchically
Root node
Sibling nodes
Root node
Child nodes
*
15. 9 TreeViews
Displays a hierarchical collection of labeled items, each represented by a TreeNode .
For a list of all members of this type, see TreeView Members .
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 .
For a list of all members of this type, see TreeNode Members .
You can add, remove, or clone a TreeNode;
when doing so, all child tree nodes are added, removed, or cloned.
*
TreeNode.Nodes Property 
Gets the collection of TreeNode objects assigned to the current tree node.
public TreeNodeCollection Nodes {get;}
The Nodes property can hold a collection of other TreeNode objects.
Each of the tree node in the collection has a Nodes property that can contain its own 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.
TreeNodeCollection class represents a collection of TreeNode objects.
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);
Adds a previously created tree node to the end of the tree node collection:
Removes the specified tree node from the tree node collection:
Remove At
Removes a tree node from the tree node collection at a specified index.
*
Common Properties
Indicates whether checkboxes appear next to nodes. True displays checkboxes. Default is False.
ImageList
Indicates the ImageList used to display icons by the nodes. An ImageList is a collection that contains a number of Image objects.
Nodes
Lists the collection of TreeNodes in the control. Contains methods Add (adds a TreeNode object), Clear (deletes the entire collection) and Remove (deletes a specific node). Removing a parent node deletes all its children.
SelectedNode
AfterSelect
Generated after selected node changes. Default when double-clicked in designer.
Fig. 15.25 TreeView properties and events.
Jozef Goetz contribution, 2012
Common Properties
Checked
Indicates whether the TreeNode is checked. (CheckBoxes property must be set to True in parent TreeView.)
FirstNode
Specifies the first node in the Nodes collection (i.e., first child in tree).
FullPath
Indicates the path of the node, starting at the root of the tree.
ImageIndex
Specifies the index of the image to be shown when the node is deselected.
LastNode
Specifies the last node in the Nodes collection (i.e., last child in tree).
NextNode
Nodes
The collection of TreeNodes contained in the current node (i.e., all the children of the current node). Contains methods Add (adds a TreeNode object), Clear (deletes the entire collection) and Remove (deletes a specific node). Removing a parent node deletes all its children.
PrevNode
SelectedImageIndex
Specifies the index of the image to use when the node is selected.
Text
Common Methods
GetNodeCount
Jozef Goetz contribution, 2012
Fig. 15.27 TreeNode Editor obtained after clicking on property Nodes
Delete current node
Outline
1 // Fig. 13.21 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;
16 private System.Windows.Forms.TreeView directoryTreeView;
18 [STAThread]
27 {
29 string[] directoryArray =
31 // returns an array of subdirectories
Class that creates children of root
Get subdirectories of root
Outline
33 try
38 // add as child of current node and recursively
39 // populate child nodes with subdirectories
40 foreach ( string directory in directoryArray ) // 1st time is "C:\\",
41 {
44
46 parentNode.Nodes.Add( myNode );
49 PopulateTreeView( directory, myNode );
// the subdirectories
*
Outline
64 private void TreeViewDirectoryStructureTest_Load(
66 {
68 // insert its subfolders
71 "C:\\", directoryTreeView.Nodes[ 0 ] ) ;//takes (name, root node’s index)
72 }
73
Outline
1 // Fig. 16.28: ed4 TreeViewDirectoryStructureForm.cs
2 // Using TreeView to display directory structure; use the button click event
// the difference here and the previuos one - here is added the button and input
3 using System; //to start fron the inputed directory
4 using System.Windows.Forms;
5 using System.IO;
8 public partial class TreeViewDirectoryStructureForm : Form
9 {
10 string substringDirectory; // store last part of full path name
// contains view of c: drive directory structure
private System.Windows.Forms.TreeView directoryTreeView;
19 public void PopulateTreeView(
21 {
23 string[] directoryArray =
24 Directory.GetDirectories( directoryValue );
27 try
30 if ( directoryArray.Length != 0 )
33 // add as a child of current node and recursively
34 // populate child nodes with subdirectories
35 foreach ( string directory in directoryArray )
36 {
37 // obtain last part of path name from the full path name
38 // by calling the GetFileNameWithoutExtension method of
39 // class Path
46
48 parentNode.Nodes.Add( myNode );
51 PopulateTreeView( directory, myNode );
64 private void enterButton_Click( object sender, EventArgs e )
65 {
71 // if not display error MessageBox
72 if ( Directory.Exists( inputTextBox.Text ) )
75 directoryTreeView.Nodes.Add( inputTextBox.Text );
82 else
84 "Directory Not Found", MessageBoxButtons.OK,
85 MessageBoxIcon.Error );
Displays icons along side of list items
*
15. 10 ListViews 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 .
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.
*
Using the ListView.ListViewItemCollection returned by this property, you can add items, remove items, and obtain a count of items
this class represents the collection of items and stores them in a ListView control.
public class ListView.ListViewItemCollection : IList, ICollection, IEnumerable
where: public virtual ListViewItem Add( ListViewItem value );
Insert -Inserts an item into the collection at the specified index
where: public ListViewItem Insert( int index, ListViewItem item );
Remove removes the specified item from the collection.
where: public virtual void Remove( ListViewItem item );
*
The ListViewItem class defines the appearance, behavior, and data associated with an item that is displayed in the ListView control.
ListViewItem objects
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.
*
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories.
For a list of all members of this type, see DirectoryInfo Members .
Provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects.
For a list of all members of this type, see FileInfo Members .
Common Properties
Determines how the user activates an item. This property takes a value in the ItemActivation enumeration. Possible values are OneClick (single-click activation), TwoClick (double-click activation, item changes color when selected) and Standard (double-click activation).
CheckBoxes
LargeImageList
Items
MultiSelect
Determines whether multiple selection is allowed. Default is True, which enables multiple selection.
SelectedItems
SmallImageList
View
Determines appearance of ListViewItems. Values LargeIcon (large icon displayed, items can be in multiple columns), SmallIcon (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).
Common Event
ItemActivate
Generated when an item in the ListView is activated. Does not specify which item is activated.
Jozef Goetz contribution, 2012
Fig. 15.30 Image Collection Editor window for an ImageList component.
It can be dragged from the ToolBox .
*
Outline
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;
13 {
15 // in directory tree
16 private System.Windows.Forms.Label currentLabel;
17 private System.Windows.Forms.Label displayLabel;
20 private System.Windows.Forms.ListView browserListView;
23 private System.Windows.Forms.ImageList fileFolder;
Outline
35 // browse directory user clicked or go up one level
36 private void browserListView_Click(
38 {
43 if ( browserListView.Items[ 0 ].Selected )
44 {
46 DirectoryInfo directoryObject =
51 LoadFilesInDirectory(
52 directoryObject.Parent.FullName );
53 }
54
55 // selected directory or file is not as the 1st item
56 else
59 string chosen =
// of the selected item (1st item in the collection)
61
63 if ( Directory.Exists( currentDirectory +
Return parent of
Test if item is selected
If first item selected go up one level
Make directory information
Outline
68 // otherwise we do
69 if ( currentDirectory == "C:\\" )
72 else
73 LoadFilesInDirectory(
87 public void LoadFilesInDirectory(
91 try
94 browserListView.Items.Clear();
95 browserListView.Items.Add( "Go Up One Level" ); // 1st item to display
96
Update to display
Outline
99 DirectoryInfo newCurrentDirectory = // if no permission, an exception is thrown
100 new DirectoryInfo( currentDirectory ); //System.IO namespace
101
103 DirectoryInfo[] directoryArray =
111 {
113 ListViewItem newDirectoryItem =
114 browserListView.Items.Add( dir.Name );
116 // set directory image
117 newDirectoryItem.ImageIndex = 0; //this value 0 was setup via line 153
// in the ImageList
118 } // Fig. 14.30
122 {
124 ListViewItem newFileItem =
125 browserListView.Items.Add( file.Name );
126
127 newFileItem.ImageIndex = 1; //this value 0 was setup via line 154
// in the ImageList
// Collection Editor – also see a few slides back 128 } // Fig. 14.30
129 } // end try
Get subdirectories of current directory, different than a former program
Get files of current directory
Add directory to list
Add file to list
Outline
136 "visible due to permission settings",
137 "Attention", 0, MessageBoxIcon.Warning );
142 // handle load event when Form displayed for first time
143 private void ListViewTest_Load(
145 {
151 "\\images\\file.bmp" );
153 fileFolder.Images.Add( folderImage );
154 fileFolder.Images.Add( fileImage );
157 LoadFilesInDirectory( currentDirectory );
158 displayLabel.Text = currentDirectory;
Outline
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.
*
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
Tab pages
Fig. 15.34 Adding TabPages to the TabControl
*
Common Properties
ItemSize
SelectedIndex
SelectedTab
TabCount
TabPages
Common Event
SelectedIndexChanged
Fig. 15.35 TabControl properties and events.
2002 Prentice Hall. All rights reserved.
Outline
3
12 {
14 private System.Windows.Forms.Label displayLabel;
17 // sizeTabPage, messageTabPage and aboutTabPage
18 private System.Windows.Forms.TabControl
22 private System.Windows.Forms.TabPage colorTabPage;
Outline
30 private System.Windows.Forms.TabPage sizeTabPage;
39 private System.Windows.Forms.TabPage messageTabPage;
46 private System.Windows.Forms.TabPage aboutTabPage;
47 private System.Windows.Forms.Label messageLabel;
56 private void blackRadioButton_CheckedChanged(
58 {
Outline
63 private void redRadioButton_CheckedChanged(
65 {
70 private void greenRadioButton_CheckedChanged(
72 {
77 private void size12RadioButton_CheckedChanged(
79 {
82 }
83
85 private void size16RadioButton_CheckedChanged(
87 {
90 }
91
Outline
93 private void size20RadioButton_CheckedChanged(
95 {
98 }
99
101 private void helloRadioButton_CheckedChanged(
103 {
108 private void goodByeRadioButton_CheckedChanged(
110 {
Outline
Software Engineering Observation 15.3
A TabPage can act as a container for a single logical group of RadioButtons, enforcing their mutual exclusivity.
*
MDI
Child window
Cannot be moved outside parent
*
Fig. 15.37 MDI parent and MDI child.
MDI parent
MDI child
MDI child
Single Document Interface (SDI)
Multiple Document Interface (MDI)
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
*
Parent and child menus can be merged
Based on MergeOrder property
Tiled windows: completely fill parent, no overlap
Either horizontal or vertical
ArrangeIcons: arranges icons for minimized windows
(c) TileHorizontal
(a) ArrangeIcons
(b) Cascade
(d) Tilevertical
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. 15.40 Minimized and maximized child windows.
*
*
Common MDI Child Properties
IsMdiChild
Indicates whether the Form is an MDI child. If True, Form is an MDI child (read-only property).
MdiParent
Common MDI Parent Properties
ActiveMdiChild
Returns the Form that is the currently active MDI child (returns null if no children are active).
IsMdiContainer
Indicates whether a Form can be an MDI. If True, the Form can be an MDI parent. Default is False.
MdiChildren
Common Method
LayoutMdi
Determines the display of child forms on an MDI parent. Takes as a parameter an MdiLayout enumeration with possible values ArrangeIcons, Cascade, TileHorizontal and TileVertical. Figure 15.42 depicts the effects of these values.
Common Event
MdiChildActivate
Fig. 15.39 MDI parent and MDI child events and properties.
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.Show();
In most cases, the parent Form creates the child, so the parentForm reference is this.
15.12  Multiple Document Interface (MDI) Windows (Cont.)
*
is setup as windowToolStripMenuItem
Property MdiWindowListItem of class MenuStrip specifies which menu, if any, displays a list of open child windows.
Separator bar and child windows
*
©1992-2011 by Pearson Education, Inc. All Rights Reserved.
©1992-2011 by Pearson Education, Inc. All Rights Reserved.
*
(c) TileHorizontal
(a) ArrangeIcons
(b) Cascade
(d) Tilevertical
Fig. 15.43 | MDI parent-window class. (Part 1 of 6.)
*
2 // Demonstrating use of MDI parent and child windows.
3 using System;
4 using System.Windows.Forms;
7 {
8 // Form demonstrates the use of MDI parent and child windows
9 public partial class UsingMDIForm : Form
10 {
Fig. 15.43 | 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.
*
18 private void csToolStripMenuItem_Click(
20 {
23 "Visual C# 2008 How to Program", "vcs2008htp" );
24 child.MdiParent = this; // set parent
25 child.Show(); // display child
26 } // end method child1ToolStripMenuItem_Click
29 private void cppToolStripMenuItem_Click(
31 {
34 "Visual C++ 2008 How to Program", "vcpp2008htp" );
35 child.MdiParent = this; // set parent
36 child.Show(); // display child
Jozef Goetz contribution, 2012
Adding a new child Form with certain properties.
*
40 private void vbToolStripMenuItem_Click(
42 {
45 "Visual Basic 2008 How to Program", "vb2008htp" );
46 child.MdiParent = this; // set parent
47 child.Show(); // display child
48 } // end method child3ToolStripMenuItem_Click
53 {
Setting the layout of child Forms.
Setting the layout of child Forms.
Setting the layout of child Forms.
MDI containers allow you to organize the placement of its child windows.
Method LayoutMdi takes a value of the MdiLayout enumeration
*
60 {
67 {
74 {
Fig. 15.43 | MDI parent-window class. (Part 5, 6 of 6.)
a) Creating a child window
b) Viewing the child window
c) Changing child window organization
d) Child windows in Cascade view
*
( 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. 15.44).
Fig. 15.44 | MDI child ChildForm. (Part 1 of 2.)
*
3 using System;
4 using System.Drawing;
5 using System.Windows.Forms;
6 using System.IO;
11 {
13 {
15 InitializeComponent();
Setting the title-bar text.
*
18
20 displayPictureBox.Image =
Derived Form inherits visual aspects
size,
color,
Outline
VisualInheritanceForm.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.
*
3 using System;
4 using System.Windows.Forms;
7 public partial class VisualInheritanceForm : Form
8 {
16 private void learnMoreButton_Click( object sender, EventArgs e )
17 {
20 "Learn More", MessageBoxButtons.OK,
*
3 using System;
4 using System.Windows.Forms;
7 public partial class VisualInheritanceTestForm :
8 VisualInheritanceForm // code for inheritance
9 {
18 {
20 "Learn the Program", MessageBoxButtons.OK,
21 MessageBoxIcon.Information );
*
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
15.14  User-Defined Controls
*
2. User-defined control can inherit from class Control and Component
1. Custom Control is a base class for the User Control classes
*
15.14 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)
*
Jozef Goetz contribution, 2012
Timers 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 – 2nd last paragraph
15.14  User-Defined Controls (Cont.)
Outline
3
18 private void clockTimer_Tick(
20 {
22 displayLabel.Text = DateTime.Now.ToLongTimeString();
*
Right click the ToolBox and select Choose Items….
In the Choose Toolbox Items dialog, click Browse…
Select the .dll file that you created.
*
New Toolbox icon
Newly inserted control
MenuStrip Properties
HasChildren Indicates whether MenuStrip has any child controls (menu items).
RightToLeft Causes text to display from right to left. This is useful for languages that are read
from right to left.
ToolStripMenuItem Properties
Checked Indicates whether a menu item is checked. The default value is false, meaning that
the menu item is unchecked.
CheckOnClick Indicates that a menu item should appear checked or unchecked as the item is clicked.
Index Specifies an item’s position in its parent menu . A value of 0 places the MenuItem at
the beginning of the menu.
MenuItems
MenuStrip and
ShortcutKey-
DisplayString
Specifies text that should appear beside a menu item for a shortcut key. If left
blank, the key names are displayed. Otherwise, the text in this property is dis played
for the shortcut key.
ShortcutKeys
Specifies the shortcut key for the menu item (e.g., <Ctrl>-F9 is equivalent to clicking
a specific item).
ShowShortcutKeys
Indicates whether a shortcut key is shown beside menu item text. The default is
true, which displays the shortcut key.
Text
Specifies the menu item’s text. To create an Alt access shortcut, precede a character
with & (e.g., &File to specify a menu named File with the letter F underlined).
Common
Click
Generated when an item is clicked or a shortcut key is used. This is the default event
when the menu is double clicked in the designer.
1 // Fig. 14.7: MenuTestForm.cs ed2. VS2005
2 // Using Menus to change font colors and styles.
3 using System;
4 using System.Drawing;
5 using System.Windows.Forms;
6
7 // our Form contains a Menu that changes the font color
8 // and style of the text displayed in Label
9 public partial class MenuTestForm : Form
10 {
18 private void aboutToolStripMenuItem_Click ( object sender, EventArgs e )
19 {
22 "About", MessageBoxButtons.OK, MessageBoxIcon.Information );
23 } // end method aboutToolStripMenuItem_Click
27 {
32 private void ClearColor()
43 {
45 ClearColor();
48 displayLabel.ForeColor = Color.Black;
49 blackToolStripMenuItem.Checked = true;
54 {
56 ClearColor();
59 displayLabel.ForeColor = Color.Blue;
60 blueToolStripMenuItem.Checked = true;
65 {
67 ClearColor();
70 displayLabel.ForeColor = Color.Red;
76 {
78 ClearColor();
81 displayLabel.ForeColor = Color.Green;
82 greenToolStripMenuItem.Checked = true;
86 private void ClearFont()
93
94 // update Menu state and set Font to Times New Roman
95 private void timesToolStripMenuItem_Click ( object sender, EventArgs e )
96 {
98 ClearFont();
101 timesToolStripMenuItem.Checked = true;
104 } // end method timesToolStripMenuItem_Click
107 private void courierToolStripMenuItem_Click (
109 {
111 ClearFont();
118
119 // update Menu state and set Font to Comic Sans MS
120 private void comicToolStripMenuItem_Click ( object sender, EventArgs e )
121 {
123 ClearFont();
126 comicToolStripMenuItem.Checked = true;
129 } // end method comicToolStripMenuItem_Click
132 private void boldToolStripMenuItem_Click ( object sender, EventArgs e )
133 {
136
137 // use logical exlusive OR to toggle bold, keep all other styles
138 displayLabel.Font = new Font(
142
144 private void italicToolStripMenuItem_Click (
146 {
149
150 // use logical exclusive OR to toggle italic, keep all other styles
151 displayLabel.Font = new Font(
displayed for each week in the calendar.
MaxDate
MaxSelectionCount
selected at once.
MonthlyBoldedDates
in the calendar.
SelectionRange
SelectionStart
Common MonthCalendar Event
calendar.
CalendarMonth Background
CustomFormat
Sets the custom format string for the user’s options.
Format
Sets the format of the date and/or time used for the
user’s options.
MinDate
ShowCheckBox
left of the selected date and time.
DateTimePicker properties
and down Buttons. This is helpful for instances
when the DateTimePicker is used to select a
time—the Buttons can be used to increase or
decrease hour, minute and second values.
Value
Common DateTimePicker Event
including when the user selects a new date or time.
1 // Fig. 15.11: DateTimePickerForm.cs
2 // Using a DateTimePicker to select a drop off time and then an estimated
//delivery date displayed (for online DVD rental)
3 using System;
4 using System.Windows.Forms;
7 {
16 {
18
19 // add extra time when items are dropped off around Sunday
20 if ( dropOffDate.DayOfWeek == DayOfWeek.Friday ||
25 outputLabel.Text = dropOffDate.AddDays( 3 ).ToLongDateString();
26 else
28 outputLabel.Text = dropOffDate.AddDays( 2 ).ToLongDateString();
29 } // end method dateTimePickerDropOff_ValueChanged
32 {
34 dateTimePickerDropOff. MinDate = DateTime.Today;
36 // user can only select days of this ye ar
37 dateTimePickerDropOff. MaxDate = DateTime.Today.AddYears( 1 );
38 } // end method DateTimePickerForm_Load
39 } // end class DateTimePickerForm
Common Properties
ActiveLinkColor
Specifies the color of the active link when clicked . Default is red.
LinkArea
Specifies which portion of text in the LinkLabel is treated as part of
the link.
LinkBehavior
Specifies the link’s behavior, such as how the link appears when the
mouse is placed over it.
LinkColor
Specifies the original color of all links before they have been visited.
Default is blue.
in the LinkLabel.
LinkVisited
If True, link appears as if it were visited (its color is changed to that
specified by property VisitedLinkColor). Default False.
Text
UseMnemonic
If True, & character in Text property acts as a shortcut (similar to
the Alt shortcut in menus).
VisitedLinkColor
Common Event
Generated when link is clicked. Default when control is double-
clicked in designer.
Items
Returns lists the collection of all items within the ListBox.
This property enables you to obtain a reference to the list of items
currently stored in the ListBox.
With this reference, you can add items, remove items, and obtain a
count of the items in the collection
public ListBox.ObjectCollection Items {get;} // returns a class object
MultiColumn
Indicates whether the ListBox can break a list into multiple
columns. Multiple columns are used to make vertical scroll bars
unnecessary.
SelectedIndex
Returns the index of the currently selected item. If the user selects
multiple items, this method arbitrarily returns one of the selected
indices; if no items have been selected, the method returns -1.
SelectedIndices
Returns a collection of the indices of all currently selected items .
SelectedItem
Returns a reference to the currently selected item (if multiple items
are selected, it returns the item with the lowest index number).
SelectedItems
SelectionMode
Determines the number of items that can be selected and the means
through which multiple items can be selected. Values None, One,
MultiSimple (multiple selection allowed) and MultiExtended
(multiple selection allowed via a combination of arrow keys, mouse
clicks and Shift and Control buttons).
Sorted
alphabetization; default is False.
selected.
changes. This is the default event when
the control is double clicked in the
designer.
CheckedListBox
Common Properties
CheckedListBox.)
CheckedItems
The collection of items that are checked. Not the same as the selected
items, which are highlighted (but not necessarily checked).
CheckedIndices
Returns indices for the items that are checked. Not the same as the
selected indices.
SelectionMode
Can only have values One (allows multiple selection) or None (does
not allow multiple selection).
Takes an index and returns true if corresponding item checked.
Common Events
ItemCheckEventArgs
Properties:
System.Object
System.EventArgs
System.Windows.Forms.ItemCheckEventArgs
CurrentValue
Unchecked or Indeterminate.
NewValue
New state of item – see line 38 in the program
Fig. 15.19 CheckedListBox properties, methods and events.
ComboBox events and
Common Properties
Value Simple means that the text portion is editable and
the list portion is always visible.
Value DropDown (the default) means that the text portion
is editable but an arrow button must be clicked to see the
list portion.
Value DropDownList means that the text portion is not
editable and the arrow button must be clicked to see the
list portion.
MaxDropDownItems
Maximum number of items to display in the drop-down list (between
1 and 100). If value is exceeded, a scroll bar appears.
SelectedIndex
Returns index of currently selected item. If there is no currently
selected item, -1 is returned.
SelectedItem
Sorted
Common Events
SelectedIndexChanged
Similar to ListBox
Raised when selected index changes (i.e., a check box has been
checked or unchecked). Default when control double-clicked in
designer.
Common
Properties
displays checkboxes. Default is False.
ImageList Indicates the ImageList used to display icons by the nodes.
An ImageList is a collection that contains a number of
Image objects.
Nodes Lists the collection of TreeNodes in the control. Contains
methods Add (adds a TreeNode object), Clear (deletes the
entire collection) and Remove (deletes a specific node). Removing
a parent node deletes all its children.
SelectedNode
in designer.
TreeNode properties
and methods
Common Properties
(CheckBoxes property must be set to True in parent
TreeView.)
FirstNode Specifies the first node in the Nodes collection (i.e., first child
in tree).
FullPath
Indicates the path of the node, starting at the root of the tree.
ImageIndex
Specifies the index of the image to be shown when the node is
deselected.
LastNode Specifies the last node in the Nodes collection (i.e., last child
in tree).
Nodes The collection of TreeNodes contained in the current node
(i.e., all the children of the current node ).
Contains methods Add (adds a TreeNode object),
Clear (deletes the entire collection) and Remove (deletes a
specific node). Removing a parent node deletes all its children.
PrevNode
SelectedImageI
ndex
Specifies the index of the image to use when the node is selected.
Text Specifies the text to display in the TreeView.
Common Methods
GetNodeCount
1 // Fig. 16.28: ed4 TreeViewDirectoryStructureForm.cs
2 // Using TreeView to display directory structure; use the button click event
// the difference here and the previuos one - here is added the button and input
3 using System; //to start fron the inputed directory
4 using System.Windows.Forms;
5 using System.IO;
8 public partial class TreeViewDirectoryStructureForm : Form
9 {
10 string substringDirectory; // store last part of full path name
// contains view of c: drive directory structure
private System.Windows.Forms.TreeView directoryTreeView;
19 public void PopulateTreeView(
21 {
23 string[] directoryArray =
24 Directory.GetDirectories( directoryValue );
27 try
30 if ( directoryArray.Length != 0 )
33 // add as a child of current node and recursively
34 // populate child nodes with subdirectories
35 foreach ( string directory in directoryArray )
36 {
37 // obtain last part of path name from the full path name
38 // by calling the GetFileNameWithoutExtension method of
39 // class Path
46
48 parentNode.Nodes.Add( myNode );
51 PopulateTreeView( directory, myNode );
64 private void enterButton_Click( object sender, EventArgs e )
65 {
71 // if not display error MessageBox
72 if ( Directory.Exists( inputTextBox.Text ) )
75 directoryTreeView.Nodes.Add( inputTextBox.Text );
82 else
84 "Directory Not Found" , MessageBoxButtons. OK,
85 MessageBoxIcon. Error );
Common Properties
Activation
Determines how the user activates an item. This property takes a
value in the ItemActivation enumeration. Possible
values are OneClick (single-click activation), TwoClick
(double-click activation, item changes color when selected) and
Standard (double-click activation).
checkboxes. Default is False.
Items
MultiSelect
True, which enables multiple selection.
SelectedItems
SmallImageList Specifies the ImageList used when displaying small icons.
View Determines appearance of ListViewItems. Values
LargeIcon (large icon displayed, items can be in multiple
columns), SmallIcon (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).
Common Event
EventArgs)
ItemActivate Generated when an item in the ListView is activated. Does
not specify which item is activated.
TabControl properties
and events
Common Properties
ItemSize
SelectedTab Indicates the TabPage that is currently selected.
TabCount
TabPages
TabControl.
TabPage is selected).
MDI Form events and
Common MDI Child
Properties
IsMdiChild Indicates whether the Form is an MDI child. If True,
Form is an MDI child (read-only property).
MdiParent Specifies the MDI parent Form of the child.
Common MDI Parent
Properties
ActiveMdiChild Returns the Form that is the currently active MDI child
(returns null if no children are active).
IsMdiContainer Indicates whether a Form can be an MDI. If True, the
Form can be an MDI parent. Default is False.
MdiChildren
Common Method
LayoutMdi
Determines the display of child forms on an MDI parent. Takes
as a parameter an MdiLayout enumeration with possible
values ArrangeIcons, Cascade,
TileHorizontal and TileVertical.
Common Event
Fig. 15.39 MDI parent and MDI child events and properties.
1 // Fig. 15.43 ed3 and ed4: UsingMDIForm.cs
2 // Demonstrating use of MDI parent and child windows.
3 using System;
4 using System.Windows.Forms;
7 {
8 // Form demonstrates the use of MDI parent and child windows
9 public partial class UsingMDIForm : Form
10 {
18 private void csToolStripMenuItem_Click(
20 {
23 "Visual C# 2008 How to Program" , "vcs2008htp" );
24 child.MdiParent = this; // set parent
25 child.Show(); // display child
27
29 private void cppToolStripMenuItem_Click(
31 {
34 "Visual C++ 2008 How to Program" , "vcpp2008htp" );
35 child.MdiParent = this; // set parent
36 child.Show(); // display child
37 } // end method child2ToolStripMenuItem_Click
40 private void vbToolStripMenuItem_Click(
42 {
45 "Visual Basic 2008 How to Program" , "vb2008htp" );
46 child.MdiParent = this; // set parent
47 child.Show(); // display child
48 } // end method child3ToolStripMenuItem_Click
53 {
60 {
67 {
74 {
77 } // end class UsingMDIForm
78 } // end namespace UsingMDI
1 // Fig. 15.44: ChildForm.cs
3 using System;
4 using System.Drawing;
5 using System.Windows.Forms;
6 using System.IO;
11 {
13 {
15 InitializeComponent();
18
20 displayPictureBox.Image =
3 using System;
4 using System.Windows.Forms;
7 public partial class VisualInheritanceForm : Form
8 {
16 private void learnMoreButton_Click( object sender, EventArgs e )
17 {
20 "Learn More", MessageBoxButtons.OK,
23 } // end class VisualInheritanceForm
2 // Derived Form using visual inheritance.
3 using System;
4 using System.Windows.Forms;
7 public partial class VisualInheritanceTestForm :
8 VisualInheritanceForm // code for inheritance
9 {
18 {
20 "Learn the Program" , MessageBoxButtons.OK,
21 MessageBoxIcon.Information );
method
OnPaint
Create a
override
OnPaint
Paint
to the original control appearance, not redesign it.
Inherit fr
om class
functionality.
PaintEventArgs
Properties
OnPai
nt
or
Paint
Graphics
Indicates the graphics object of control. Used to draw on
control.
ClipRectangle
Fig. 13.41