Title: Graphical User Interface
114
- Graphical User Interface
- Concepts Part 2
2OBJECTIVES
- In this chapter you will learn
- To create menus, tabbed windows and multiple
document interface (MDI) programs. - To use the ListView and TreeView controls for
displaying information. - To create hyperlinks using the LinkLabel control.
- To display lists of information in ListBox and
ComboBox controls. - To input date and time data with the
DateTimePicker. - To create custom controls.
3- 14.1 Introduction
- 14.2 Menus
- 14.3 MonthCalendar Control
- 14.4 DateTimePicker Control
- 14.5 LinkLabel Control
- 14.6 ListBox Control
- 14.7 CheckedListBox Control
- 14.8 ComboBox Control
- 14.9 TreeView Control
- 14.10 ListView Control
- 14.11 TabControl Control
- 14.12 Multiple Document Interface (MDI) Windows
- 14.13 Visual Inheritance
- 14.14 User-Defined Controls
- 14.15 Wrap-Up
4Fig. 14.1 Menus, submenus and menu items
5Fig. 14.2 Editing menus in Visual Studio.
6Fig. 14.3 Adding ToolStripMenuItems to a
MenuStrip.
7Look-and-Feel Observation 14.1
- Buttons can have access shortcuts. Place the
symbol immediately before the desired character
in the Buttons label. To press the button by
using its access key in the running application,
the user presses Alt and the underlined character.
8Fig. 14.4 Setting a menu items shortcut keys.
9Fig. 14.5 Menu item options.
10Fig. 14.6 MenuStrip and ToolStripMenuItem
properties and an event. (Part 1 of 2.)
11Fig. 14.6 MenuStrip and ToolStripMenuItem
properties and an event. (Part 2 of 2.)
12Look-and-Feel Observation 14.2
- It is a convention to place an ellipsis ( ) after
the name of a menu item that when selected,
displays a dialog (e.g. Save As...). Menu items
that produce an immediate action without
prompting the user for more information (e.g.
Save) should not have an ellipsis following their
name.
13Outline
MenuTestForm.cs (1 of 8)
14Outline
MenuTestForm.cs (2 of 8)
15Outline
MenuTestForm.cs (3 of 8)
16Outline
MenuTestForm.cs (4 of 8)
17Outline
MenuTestForm.cs (5 of 8)
18Outline
MenuTestForm.cs (6 of 8)
19Outline
MenuTestForm.cs (7 of 8)
20Outline
MenuTestForm.cs (8 of 8)
21Software Engineering Observation 14.1
- The mutual exclusion of menu items is not
enforced by the MenuStrip, even when the Checked
property is true. You must program this behavior.
22Fig. 14.8 MonthCalendar control.
23Fig. 14.9 MonthCalendar properties and an
event.
24Fig. 14.10 DateTimePicker properties and an
event. (Part 1 of 2.)
25Fig. 14.10 DateTimePicker properties and an
event. (Part 2 of 2.)
26Outline
DateTimePickerForm.cs (1 of 3)
27Outline
DateTimePickerForm.cs (2 of 3)
28Outline
DateTimePickerForm.cs (3 of 3)
29Look-and-Feel Observation 14.3
- A LinkLabel is the preferred control for
indicating that the user can click a link to jump
to a resource such as a Web page, though other
controls can perform similar tasks.
30Fig. 14.12 LinkLabel control in running
program.
31Fig. 14.13 LinkLabel properties and an event.
(Part 1 of 2.)
32Fig. 14.13 LinkLabel properties and an event.
(Part 2 of 2.)
33Outline
LinkLabelTestForm.cs (1 of 4)
34Outline
LinkLabelTestForm.cs (2 of 4)
35Outline
LinkLabelTestForm.cs (3 of 4)
36Outline
LinkLabelTestForm.cs (4 of 4)
37Fig. 14.15 ListBox and CheckedListBox on a
Form.
38Fig. 14.16 ListBox properties, methods and an
event. (Part 1 of 2.)
39Fig. 14.16 ListBox properties, methods and an
event. (Part 2 of 2.)
40Fig. 14.17 String Collection Editor.
41Outline
ListBoxTestForm.cs (1 of 3)
42Outline
ListBoxTestForm.cs (2 of 3)
43Outline
ListBoxTestForm.cs (3 of 3)
44Common Programming Error 14.1
- The IDE displays an error message if you attempt
to set the SelectionMode property to MultiSimple
or MultiExtended in the Properties window of a
CheckedListBox. If this value is set
programmatically, a runtime error occurs.
45Fig. 14.19 CheckedListBox properties, methods
and events. (Part 1 of 2.)
46Fig. 14.19 CheckedListBox properties, methods
and events. (Part 2 of 2.)
47Outline
CheckedListBoxTestForm.cs (1 of 3)
48Outline
CheckedListBoxTestForm.cs (2 of 3)
49Outline
CheckedListBoxTestForm.cs (3 of 3)
50Fig. 14.21 ComboBox demonstration.
51Look-and-Feel Observation 14.4
- Use a ComboBox to save space on a GUI. A
disadvantage is that, unlike with a ListBox, the
user cannot see available items without expanding
the drop-down list.
52Fig. 14.22 ComboBox properties and an event.
(Part 1 of 2.)
53Fig. 14.22 ComboBox properties and an event.
(Part 2 of 2.)
54Outline
- comboBoxTextForm.Cs
- (1 of 3)
55Outline
- comboBoxTextForm.Cs
- (2 of 3)
56Outline
- comboBoxTextForm.Cs
- (3 of 3)
57Look-and-Feel Observation 14.5
- Make lists (such as ComboBoxes) editable only if
the program is designed to accept user-submitted
elements. Otherwise, the user might try to enter
a custom item that is improper for the purposes
of your application.
58Fig. 14.24 TreeView displaying a sample tree.
59Fig. 14.25 TreeView properties and an event.
60Fig. 14.26 TreeNode properties and methods.
(Part 1 of 2.)
61Fig. 14.26 TreeNode properties and methods.
(Part 2 of 2.)
62Fig. 14.27 TreeNode Editor.
63Outline
TreeViewDirectoryStructureForm.cs (1 of 4)
64Outline
TreeViewDirectoryStructureForm.cs (2 of 4)
65Outline
TreeViewDirectoryStructureForm.cs (3 of 4)
66Outline
TreeViewDirectoryStructureForm.cs (4 of 4)
67Fig. 14.29 ListView properties and an event.
(Part 1 of 2.)
68Fig. 14.29 ListView properties and an event.
(Part 2 of 2.)
69Fig. 14.30 Image Collection Editor window for
an ImageList component.
70Outline
ListViewTestForm.cs (1 of 7)
71Outline
ListViewTestForm.cs (2 of 7)
72Outline
ListViewTestForm.cs (3 of 7)
73Outline
ListViewTestForm.cs (4 of 7)
74Outline
ListViewTestForm.cs (5 of 7)
75Outline
ListViewTestForm.cs (6 of 7)
76Outline
ListViewTestForm.cs (7 of 7)
77Software Engineering Observation 14.2
- When designing applications that run for long
periods of time, you might choose a large initial
delay to improve performance throughout the rest
of the program. However, in applications that run
for only short periods of time, developers often
prefer fast initial loading times and small
delays after each action.
78Fig. 14.32 Tabbed windows in Visual Studio.
79Fig. 14.33 TabControl with TabPages example.
80Fig. 14.34 TabPages added to a TabControl.
81Fig. 14.35 TabControl properties and an event.
82Outline
UsingTabsForm.cs (1 of 4)
83Outline
UsingTabsForm.cs (2 of 4)
84Outline
UsingTabsForm.cs (3 of 4)
85Outline
UsingTabsForm.cs (4 of 4)
86Software Engineering Observation 14.3
- A TabPage can act as a container for a single
logical group of RadioButtons, enforcing their
mutual exclusivity. To place multiple RadioButton
groups inside a single TabPage, you should group
RadioButtons within Panels or GroupBoxes
contained within the TabPage.
87Fig. 14.37 MDI parent window and MDI child
windows.
88Fig. 14.38 SDI and MDI forms.
89Fig. 14.39 MDI parent and MDI child properties,
method and event.
90Good Programming Practice 14.1
- When creating MDI applications, include a menu
that displays a list of the open child windows.
This helps the user select a child window
quickly, rather than having to search for it in
the parent window.
91Fig. 14.40 Minimized and maximized child
windows.
92Fig. 14.41 MenuItem property MdiList example.
93Fig. 14.42 MdiLayout enumeration values.
94Outline
UsingMDIForm.cs (1 of 4)
95Outline
UsingMDIForm.cs (2 of 4)
96Outline
UsingMDIForm.cs (3 of 4)
97Outline
UsingMDIForm.cs (4 of 4)
98Outline
ChildForm.cs
99Outline
VisualInheritanceForm.cs
100Fig. 14.46 Form demonstrating visual
inheritance.
101Outline
VisualInheritanceTestForm.cs (1 of 2)
102Outline
VisualInheritanceTestForm.cs (2 of 2)
103Fig. 14.48 Custom control creation.
104Outline
ClockUserControl.cs
105Fig. 14.50 Custom-control creation.
106Fig. 14.51 Custom control added to the ToolBox.
107Fig. 14.52 Custom control added to a Form.