1 of 107

Windows Applications

Chapter 7b

2 of 107

Menus

  • Menus are used to provide groups of related commands for Windows applications.
  • Although these commands depend on the program, some—such as Open and Save—are common to many applications.

3 of 107

4 of 107

5 of 107

6 of 107

7 of 107

8 of 107

9 of 107

10 of 107

11 of 107

12 of 107

13 of 107

14 of 107

15 of 107

16 of 107

17 of 107

Link Labels

  • The LinkLabel control displays links to other objects, 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 the behavior of a hyperlink in a Web page. The link can change color to indicate whether the link is new, visited or active.
  • When clicked, the LinkLabel generates a LinkClicked event .
  • Class LinkLabel is derived from class Label and therefore inherits all of class Label’s functionality.

18 of 107

19 of 107

20 of 107

21 of 107

22 of 107

ListBoxes and CheckedList Boxes

  • The ListBox control allows the user to view and select from multiple items in a list.
  • ListBoxes are static GUI entities, which means that users cannot enter new items in the list.
  • The CheckedListBox control extends a ListBox by including check boxes next to each item in the list. This allows users to place checks on multiple items at once, as is possible in a CheckBox control.

23 of 107

24 of 107

25 of 107

26 of 107

27 of 107

28 of 107

29 of 107

30 of 107

31 of 107

32 of 107

33 of 107

34 of 107

35 of 107

ComboBox

  • The ComboBox control combines TextBox features with a drop-down list. A drop-down list is a GUI component that contains a list from which values can be chosen.
  • It usually appears as a text box with a down arrow to its right. By default, the user can enter text into the text box or click the down arrow to display a list of predefined items. If a user chooses
  • an element from this list, that element is displayed in the text box. If the list contains more
  • elements than can be displayed in the drop-down list, a scrollbar appears. The maximum
  • number of items that a drop-down list can display at one time is set by property MaxDrop-
  • DownItems.

36 of 107

37 of 107

38 of 107

39 of 107

40 of 107

41 of 107

42 of 107

TreeViews

  • The TreeView control displays nodes hierarchically on 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 the root node (a TreeView can
  • have multiple roots).

43 of 107

44 of 107

45 of 107

46 of 107

47 of 107

48 of 107

49 of 107

50 of 107

51 of 107

52 of 107

53 of 107

54 of 107

ListViews

  • The ListView control is similar to a ListBox, in that both display lists from which the
  • user can select one or more items (to see an example of a ListView, look ahead to the
  • output of Fig. 13.24). The important difference between the two classes is that a List-
  • View can display icons alongside the list items in a variety of ways (controlled by its ImageList
  • property). Property MultiSelect (a boolean) determines whether multiple
  • items can be selected. Checkboxes can be included by setting property CheckBoxes (a
  • boolean) to True, making the ListView’s appearance similar to that of a
  • CheckedListBox. The View property specifies the layout of the ListBox. Property
  • Activation determines the method by which the user selects a list item.

55 of 107

56 of 107

57 of 107

58 of 107

59 of 107

60 of 107

61 of 107

62 of 107

63 of 107

64 of 107

65 of 107

66 of 107

TabControl

  • The TabControl control creates tabbed windows, such as those we have seen in the Visual
  • Studio .NET IDE (Fig. 13.25). This allows the programmer to design user interfaces
  • that fit a large number of controls or a large amount of data without using up valuable
  • screen “real estate.”
  • TabControls contain TabPage objects, which are similar to Panels and Group-
  • Boxes in that TabPages also can contain controls. The programmer first adds controls to
  • the TabPage objects, then adds the TabPages to the TabControl. Only one TabPage
  • is displayed at a time. Figure 13.26 depicts a sample TabControl.
  • Programmers can add TabControls visually by dragging and dropping them onto a
  • form in design mode. To add TabPages in the Visual Studio .NET designer, right-click
  • the TabControl, and select Add Tab (Fig. 13.27). Alternatively, click the TabPages
  • collection in the Properties window, and add tabs in the dialog that appears. To change a
  • tab label, set the Text property of the TabPage.

67 of 107

68 of 107

69 of 107

70 of 107

71 of 107

72 of 107

73 of 107

74 of 107

75 of 107

76 of 107

77 of 107

78 of 107

Multiple-Document-Interface (MDI) Windows

  • Multiple document interface (MDI) programs (such as PaintShop Pro and Adobe Photoshop) enable users to edit multiple documents at once. MDI programs also tend to be more complex—PaintShop Pro and Photoshop have a greater number of image-editing features than does Paint. Until now, we had not mentioned that the applications we created were SDI applications.

79 of 107

80 of 107

81 of 107

82 of 107

83 of 107

84 of 107

85 of 107

86 of 107

87 of 107

88 of 107

89 of 107

90 of 107

Virtual Inheritance

  • Visual inheritance enables developers to achieve visual consistency across applications
  • by reusing code. For example, a company could define a base form that contains a
  • product’s logo, a static background color, a predefined menu bar and other elements. Programmers
  • then could use the base form throughout an application for purposes of uniformity
  • and product branding.

91 of 107

92 of 107

93 of 107

94 of 107

95 of 107

96 of 107

97 of 107

98 of 107

User Defined Controls

  • The .NET Framework allows programmers to create custom controls that inherit from a variety
  • of classes. These custom controls appear in the user’s Toolbox and can be added to
  • Forms, Panels or GroupBoxes in the same way that we add Buttons, Labels, and
  • other predefined controls. The simplest way to create a custom control is to derive a class
  • from an existing Windows Forms control, such as a Label. This is useful if the programmer
  • wants to include functionality of an existing control, rather than having to reimplement
  • the existing control in addition to including the desired new functionality. For example, we
  • can create a new type of label that behaves like a normal Label but has a different appearance.
  • We accomplish this by inheriting from class Label and overriding method On-
  • Paint.

99 of 107

100 of 107

101 of 107

102 of 107

103 of 107

104 of 107

105 of 107

106 of 107

107 of 107