0% found this document useful (0 votes)
12 views

DDDFF

1. The document discusses various Windows Forms controls that can be used to build graphical user interfaces, including menus, date/time pickers, link labels, list boxes, combo boxes, tree views, list views, and tab controls. 2. It also covers topics like creating custom controls, using visual inheritance to reuse functionality from other forms/controls, and building multiple document interface applications with parent and child windows. 3. The wrap-up section emphasizes that designing user-friendly graphical user interfaces is an essential programming skill, and that Visual Studio makes GUI development quick and easy.

Uploaded by

mnrzid300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

DDDFF

1. The document discusses various Windows Forms controls that can be used to build graphical user interfaces, including menus, date/time pickers, link labels, list boxes, combo boxes, tree views, list views, and tab controls. 2. It also covers topics like creating custom controls, using visual inheritance to reuse functionality from other forms/controls, and building multiple document interface applications with parent and child windows. 3. The wrap-up section emphasizes that designing user-friendly graphical user interfaces is an essential programming skill, and that Visual Studio makes GUI development quick and easy.

Uploaded by

mnrzid300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

630 Chapter 15 Graphical User Interfaces with Windows Forms: Part 2

the Choose Toolbox Items dialog (Fig. 15.52). If it’s not already checked, check
this item. Click OK to add the item to the Toolbox. This control can now be add-
ed to the Form as if it were any other control.

Fig. 15.52 | Custom control added to the ToolBox.

15.15 Wrap-Up
Many of today’s commercial apps provide GUIs that are easy to use and manipulate. Because
of this demand for user-friendly GUIs, the ability to design sophisticated GUIs is an essential
programming skill. Visual Studio’s IDE makes GUI development quick and easy. In
Chapters 14 and 15, we presented basic Windows Forms GUI development techniques. In
Chapter 15, we demonstrated how to create menus, which provide users easy access to an
app’s functionality. You learned the DateTimePicker and MonthCalendar controls, which
allow users to input date and time values. We demonstrated LinkLabels, which are used to
link the user to an app or a web page. You used several controls that provide lists of data to
the user—ListBoxes, CheckedListBoxes and ListViews. We used the ComboBox control to
create drop-down lists, and the TreeView control to display data in hierarchical form. We
then introduced complex GUIs that use tabbed windows and multiple document interfaces.
The chapter concluded with demonstrations of visual inheritance and creating custom con-
trols. In Chapter 16, we introduce string and character processing.

Summary
Section 15.2 Menus
• Menus provide groups of related commands for Windows Forms apps.
• An expanded menu lists menu items and submenus.
• A menu that contains a menu item is called that menu item’s parent menu. A menu item that
contains a submenu is considered to be the parent of that submenu.
Summary 631

• All menus and menu items can have shortcut keys.


• Some menu items display checkmarks, indicating that multiple options on the menu can be se-
lected at once.
• The MenuStrip control is used to create menus in a GUI.
• Top-level menus and their menu items are represented using type ToolStripMenuItem.
• To create an access shortcut, type an ampersand (&) before the character to be underlined.
• To add other shortcut keys, set the ShortcutKeys property of the ToolStripMenuItem.
• You can hide shortcut keys by setting property ShowShortcutKeys to false. You can modify how
shortcut keys are displayed in the menu item by modifying property ShortcutKeyDisplayString.
• A menu item’s Checked property is used to display a check to the left of the menu item.

Section 15.3 MonthCalendar Control


• The MonthCalendar control displays a monthly calendar.
• The user can select a date from the currently displayed month or navigate to another month.
• A MonthCalendar’s DateChanged event occurs when a new date is selected.

Section 15.4 DateTimePicker Control


• The DateTimePicker control can be used to retrieve date and/or time information from the user.
• Property Format of class DateTimePicker specifies the user’s selection options.
• The DateTimePicker’s ValueChanged event is raised when the selected value is changed.

Section 15.5 LinkLabel Control


• The LinkLabel control displays links to other resources, such as files or web pages.
• A LinkLabel appears as underlined text (colored blue by default). When the mouse moves over
the link, the pointer changes to a hand; this is similar to a hyperlink in a web page.
• The link can change color to indicate whether the link is new, previously visited or active.
• When clicked, the LinkLabel generates a LinkClicked event.

Section 15.6 ListBox Control


• The ListBox control allows the user to view and select items in a list.
• ListBox property SelectionMode determines the number of items that can be selected.
• The SelectedIndexChanged event of class ListBox occurs when the user selects a new item.
• Property Items returns all the list items as a collection.
• Property SelectedItem returns the currently selected item.
• Use method Add to add an item to the ListBox’s Items collection.
• You can add items to ListBoxes and CheckedListBoxes visually by using the Items property in
the Properties window.

Section 15.7 CheckedListBox Control


• The CheckedListBox control extends a ListBox by including a checkbox next to each item.
• Items can be added via methods Add and AddRange or through the String Collection Editor.
• CheckedListBoxes imply that multiple items can be checked.
• CheckedListBox event ItemCheck occurs when a user checks or unchecks a CheckedListBox item.
632 Chapter 15 Graphical User Interfaces with Windows Forms: Part 2

Section 15.8 ComboBox Control


• The ComboBox control combines TextBox features with a drop-down list.
• Property MaxDropDownItems specifies the maximum number of items that can display at one
time.
• You can add objects to collection Items programmatically, using methods Add and AddRange, or
visually, with the String Collection Editor.
• Property DropDownStyle determines the type of ComboBox and is represented as a value of the Com-
boBoxStyle enumeration, which contains values Simple, DropDown and DropDownList.
• There can be at most one selected item in a ComboBox (if none, then SelectedIndex is -1).
• When the selected item changes in a ComboBox, a SelectedIndexChanged event occurs.

Section 15.9 TreeView Control


• The TreeView control displays nodes hierarchically in a tree.
• Traditionally, nodes are objects that contain values and can refer to other nodes.
• A parent node contains child nodes, and the child nodes can be parents to other nodes.
• Two child nodes that have the same parent node are considered sibling nodes.
• A tree is a collection of nodes, usually organized in a hierarchical manner. The first parent node
of a tree is a root node—there can be multiple root nodes.
• TreeView controls are useful for displaying hierarchical information.
• In a TreeView, a parent node can be expanded or collapsed by clicking the plus box or minus box
to its left. Nodes without children do not have these boxes.
• The nodes displayed in a TreeView are instances of class TreeNode.
• Each TreeNode has a Nodes collection (type TreeNodeCollection), containing a list of TreeNodes.
• To add nodes to a TreeView visually, click the ellipsis next to property Nodes in the Properties win-
dow. This opens the TreeNode Editor, which displays an empty tree representing the TreeView.
• To add nodes programmatically, you must create a root TreeNode object and pass it a string to
display. Then call method Add to add this new TreeNode to the TreeView’s Nodes collection.

Section 15.10 ListView Control


• The ListView control is similar to a ListBox in that both display lists from which the user can
select one or more items. ListView is more flexible and can display items in different formats.
• Property MultiSelect (a bool) determines whether multiple items can be selected.
• To display images, an ImageList component is required.
• Property SmallImageList of class ListView sets the ImageList for the small icons.
• Property LargeImageList of class ListView sets the ImageList for large icons.
• The items in a ListView are each of type ListViewItem.

Section 15.11 TabControl Control


• The TabControl control creates tabbed windows.
• TabControls contain TabPage objects. Only one TabPage is displayed at a time.
• You can add TabControls visually by dragging and dropping them on a Form in Design mode.
• To add TabPages in Design mode, open the TabControl’s smart tasks menu and click Add Tab, or
click the TabPages property in the Properties window, and add tabs in the dialog that appears.
• Each TabPage raises a Click event when its tab is clicked.
Terminology 633

Section 15.12 Multiple Document Interface (MDI) Windows


• The app window of a multiple document interface (MDI) program is called the parent window,
and each window inside the app is referred to as a child window.
• Child windows cannot be parents themselves and cannot be moved outside their parent.
• To create an MDI Form, create a new Form and set its IsMdiContainer property to true.
• To add a child Form to the parent, create a new child Form object, set its MdiParent property to
the parent Form and call the child Form’s Show method.
• Property MdiWindowListItem of class MenuStrip specifies which menu, if any, displays a list of
open child windows.
• MDI containers allow you to organize the placement of child windows. The child windows in
an MDI app can be arranged by calling method LayoutMdi of the parent Form.

Section 15.13 Visual Inheritance


• Visual inheritance allows you to create a new Form by inheriting from an existing Form. The de-
rived Form class contains the functionality of its base class.
• Visual inheritance can also be applied with other controls as well.
• Visual inheritance enables you to achieve visual consistency across apps by reusing code.
• A reusable class is typically placed in a class library.
• When you compile a class library, the compiler will create a .dll file, known as a dynamically
linked library—a way to package classes that you can reference from other apps.

Section 15.14 User-Defined Controls


• The .NET Framework allows you to create custom controls.
• Custom controls can appear in the user’s Toolbox and can be added to Forms, Panels or Group-
Boxes in the same way that Buttons, Labels and other predefined controls are added.

• The simplest way to create a custom control is to derive a class from an existing control, such as
a Label. This is useful if you want to add functionality to an existing control, rather than replac-
ing it with one that provides the desired functionality.
• To create a new control composed of existing controls, use class UserControl.
• Controls added to a custom control are called constituent controls.
• A programmer can create a brand-new control by inheriting from class Control. This class does
not define any specific behavior; that task is left to you.
• Timers are non-visual components that generate Tick events at a set interval. This interval is set
by the Timer’s Interval property, which defines the number of milliseconds (thousandths of a
second) between events. Timers are disabled by default.

Terminology
access shortcut CheckedListBox class
Activation property of class ListView child node
ActiveMdiChild property of class Form child window
AddDays method of struct DateTime Clear method of class Graphics
AddYears method of struct DateTime Click event of class ToolStripMenuItem
Application class ClipRectangle property of class
cascaded window PaintEventArgs
CheckBoxes property of class ListView ComboBox class
Checked property of class ToolStripMenuItem ComboBoxStyle enumeration
634 Chapter 15 Graphical User Interfaces with Windows Forms: Part 2

constituent controls MinDate property of class DateTimePicker


CustomFormat property of class DateTimePicker MonthCalendar class
Date property of struct DateTime multiple document interface (MDI)
DateChanged event of class MonthCalendar MultiSelect property of class ListView
DateTime struct Name property of class DirectoryInfo
DateTimePicker class Name property of class FileInfo
DateTimePickerFormat enumeration node
DayOfWeek enumeration Nodes collection
DayOfWeek property of struct DateTime Now property of struct DateTime
DirectoryInfo class ObjectCollection class
.dll file OnPaint method of class Control
DrawEllipse method of class Graphics PaintEventArgs class
DrawPie method of class Graphics parent node
DrawRectangle method of class Graphics Parent property of class DirectoryInfo
DropDownStyle property of class ComboBox parent window
dynamically linked library Path class
Exists method of class Directory Process class
Exit method of class Application root node
FileInfo class SelectedIndex property of class ComboBox
FillEllipse method of class Graphics SelectedIndex property of class ListBox
FillPie method of class Graphics SelectedIndexChanged event of class ComboBox
FillRectangle method of class Graphics SelectedIndexChanged event of class ListBox
Format property of class DateTimePicker SelectedIndices property of class ListBox
FullName property of class DirectoryInfo SelectedItem property of class ComboBox
FullName property of class FileInfo SelectedItem property of class ListBox
GetDirectories method of class DirectoryInfo SelectedItems property of class ListBox
GetFiles method of class DirectoryInfo SelectionMode enumeration
GetSelected method of class ListBox SelectionMode property of class ListBox
Graphics property of class PaintEventArgs separator bar
hotkey ShortcutKeyDisplayString property of class
ImageIndex property of class ListViewItem ToolStripMenuItem
ImageList class ShortcutKeys property of class
Images property of class ImageList ToolStripMenuItem
Interval property of class Timer ShowShortcutKeys property of class
IsMdiContainer property of class Form ToolStripMenuItem
ItemCheck event of class CheckedListBox sibling node
Items property of class ComboBox Single document interface (SDI)
Items property of class ListBox SmallImageList property of class ListView
keyboard shortcut Start method of class Process
LargeImageList property of class ListView System.Diagnostics namespace
LinkLabel class TabControl class
ListBox class TabPage class
ListView class TabPages property of class TabControl
ListViewItem class Text property of class TabPage
MaxDate property of class DateTimePicker Tick event of class Timer
MaxDropDownItems property of class ComboBox tiled window
MdiChildren property of class Form TimeOfDay property of struct DateTime
MdiParent property of class Form Timer class
MdiWindowListItem property of class MenuStrip ToLongDateString method of struct DateTime
MenuStrip class ToLongTimeString method of struct DateTime
Self-Review Exercises 635

ToolStripMenuItem class UserControl class


tree Value property of class DateTimePicker
TreeNode class ValueChanged event of class DateTimePicker
TreeNodeCollection type verbatim string
TreeView class View property of class ListView
TreeViewEventArgs class visual inheritance

Self-Review Exercises
15.1 State whether each of the following is true or false. If false, explain why.
a) Menus provide groups of related classes.
b) Menu items can display ComboBoxes, checkmarks and access shortcuts.
c) The ListBox control allows only single selection (like a RadioButton).
d) A ComboBox control typically has a drop-down list.
e) Deleting a parent node in a TreeView control deletes its child nodes.
f) The user can select only one item in a ListView control.
g) A TabPage can act as a container for RadioButtons.
h) An MDI child window can have MDI children.
i) MDI child windows can be moved outside the boundaries of their parent window.
j) There are two basic ways to create a customized control.
15.2 Fill in the blanks in each of the following statements:
a) Method of class Process can open files and web pages, similar to the Run...
command in Windows.
b) If more elements appear in a ComboBox than can fit, a(n) appears.
c) The top-level node in a TreeView is the node.
d) A(n) and a(n) can display icons contained in an ImageList control.
e) The property allows a menu to display a list of active child windows.
f) Class allows you to combine several controls into a single,custom control.
g) The saves space by layering TabPages on top of each other.
h) The window layout option makes all MDI windows the same size and layers
them so every title bar is visible (if possible).
i) are typically used to display hyperlinks to other resources, files or web pages.

Answers to Self-Review Exercises


15.1 a) False. Menus provide groups of related commands. b) True. c) False. It can have single
or multiple selection. d) True. e) True. f) False. The user can select one or more items. g) True.
h) False. Only an MDI parent window can have MDI children. An MDI parent window cannot be
an MDI child. i) False. MDI child windows cannot be moved outside their parent window. j) False.
There are three ways: 1) Derive from an existing control, 2) use a UserControl or 3) derive from
Control and create a control from scratch.

15.2 a) Start. b) scrollbar. c) root. d) ListView, TreeView. e) MdiWindowListItem. f) UserCon-


trol. g) TabControl. h) Cascade. i) LinkLabels.

Exercises
15.3 (Using ComboBoxes) Write an app that displays the names of 15 states in a ComboBox. When
an item is selected from the ComboBox, remove it.
15.4 (Using ComboBoxes and ListBoxes) Modify your solution to the previous exercise to add a
ListBox. When the user selects an item from the ComboBox, remove the item from the ComboBox and

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy