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.

  • All menus and menu items can have shortcut keys.

  • Some menu items display checkmarks, indicating that multiple options on the menu can be selected 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.

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 ComboBoxStyle 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 window. 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.

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 derived Form class contains the functionality of its base class.

  • Visual inheritance also can 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 replacing 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset