Presentation is loading. Please wait.

Presentation is loading. Please wait.

Some Interesting Controls. Controls We've UsedNew Controls LabelListBox TextBoxCheckedListBox ComboBoxTabControl ButtonTabPage Menu MenuItem TreeView.

Similar presentations


Presentation on theme: "Some Interesting Controls. Controls We've UsedNew Controls LabelListBox TextBoxCheckedListBox ComboBoxTabControl ButtonTabPage Menu MenuItem TreeView."— Presentation transcript:

1 Some Interesting Controls

2 Controls We've UsedNew Controls LabelListBox TextBoxCheckedListBox ComboBoxTabControl ButtonTabPage Menu MenuItem TreeView TreeNode PictureBox

3 ListBoxes and CheckedListBoxes ListBox –View and select from multiple items –Scroll bar appears if necessary CheckedListBox –Items have checkbox –Select multiple items at same time –Scroll bar appears if necessary

4 ListBoxes and CheckedListBoxes

5 ListBoxes ListBox properties, methods and events

6 ListBoxes

7

8

9 CheckedListBoxes CheckedListBox properties, methods and events.

10 CheckedListBox

11 ListBox

12 ListBox Control Public Class ListBox Inherits ListControl The ListBox control enables you to display a list of items to the user that the user can select by clicking. A ListBox control can provide single or multiple selections using the SelectionMode property. The ListBox also provides the MultiColumn property to enable the display of items in columns instead of a straight vertical list of items. This allows the control to display more visible items and prevents the need for the user to scroll to an item. In addition to display and selection functionality, the ListBox also provides features that enable you to efficiently add items to the ListBox and to find text within the items of the list.

13 ListBox Control (continued) Public Class ListBox Inherits ListControl The BeginUpdate and EndUpdate methods enable you to add a large number of items to the ListBox without the control being repainted each time an item is added to the list. The FindString and FindStringExact methods enable you to search for an item in the list that contains a specific search string. The Items, SelectedItems, and SelectedIndices properties provide access to the three collections that are used by the ListBox.

14 CheckedListBox Control

15 Public Class CheckedListBox Inherits ListBox This control presents a list of items that the user can navigate by using the keyboard or the scrollbar on the right side of the control. The user can place a check mark by one or more items and the checked items can be navigated with the CheckedListBox.CheckedItemCollection and CheckedListBox.CheckedIndexCollection. To add objects to the list at run time, assign an array of object references with the AddRange method. The list then displays the default string value for each object. You can add individual items to the list with the Add method. The CheckedListBox object supports three states through the CheckState enumeration: Checked, Indeterminate, and Unchecked. You must set the state of Indeterminate in the code because the user interface for a CheckedListBox does not provide a mechanism to do so. If UseTabStops is true, the CheckedListBox will recognize and expand tab characters in an item's text, creating columns. However, the tab stops are present and cannot be changed.

16 The CheckedListBox class supports the following three indexed collections All items contained in the CheckedListBox control. –CheckedListBox.ObjectCollection Checked items (including items in an indeterminate state), which is a subset of the items contained in the CheckedListBox control. –CheckedListBox.CheckedItemCollection Checked indexes, which is a subset of the indexes into the items collection. These indexes specify items in a checked or indeterminate state. –CheckedListBox.CheckedIndexCollection

17 Tab Control –Creates tabbed windows –Saves space using TabPage objects TabPage objects –Similar to Panels and GroupBoxes –Can contain controls

18 Tab Control

19

20

21 TabControl properties and events.

22 Tab Control

23

24 Public Class TabControl Inherits Control A TabControl contains tab pages, which are represented by TabPage objects that you add through the Controls property. Note The following events are not raised for the TabControl class unless there is at least one TabPage in the TabControl.TabPages collection: Control.Click, Control.DoubleClick, Control.MouseDown, Control.MouseUp, Control.MouseHover, Control.MouseEnter, Control.MouseLeave and Control.MouseMove. If there is at least one TabPage in the collection, and the user interacts with the tab control’s header (where the TabPage names appear), the TabControl raises the appropriate event. However, if the user interaction is within the ClientRectangle of the tab page, the TabPage raises the appropriate event.

25 TabPage Control

26 Public Class TabPage Inherits Panel Represents a single tab page in a TabControl. For more information about how this control responds to the Focus and Select methods, see the following Control members: CanFocus, CanSelect, Focused, ContainsFocus, Focus, Select.

27 Menus Menu –Groups related commands –Organize without “cluttering” GUI Menu items –Commands or options in menu Sub-menu –Menu within a menu Hot keys –Alt key shortcuts Press Alt + underlined letter in desired menu item

28 Menus

29

30

31 MainMenu and MenuItem properties and events.

32 MainMenu Class

33 Public Class MainMenu Inherits Menu Represents the menu structure of a form. The MainMenu control represents the container for the menu structure of a form. A menu is composed of MenuItem objects that represent the individual menu commands in the menu structure. Each MenuItem can be a command for your application or a parent menu for other submenu items. To bind the MainMenu to the Form that will display it, assign the MainMenu to the Menu property of the Form.

34 MainMenu Class (continued) You can create different MainMenu objects to represent different menu strutures for your form. If you want to reuse the menu structure contained in a specific MainMenu, you can use its CloneMenu method to create a copy. Once you have a copy of the menu structure, you can make the appropriate modifications for your new menu structure.

35 MenuItem Control

36 Public Class MenuItem Inherits Menu Represents an individual item that is displayed within a MainMenu or ContextMenu. In order for a MenuItem to be displayed, you must add it to a MainMenu or ContextMenu. To create submenus, you can add MenuItem objects to the MenuItems property of the parent MenuItem. The MenuItem class provides properties that enable you to configure the appearance and functionality of a menu item. –To display a check mark next to a menu item, use the Checked property. You can use this feature to identify a menu item that is selected in a list of mutually exclusive menu items. For example, if you have a set of menu items for setting the color of text in a TextBox control, you can use the Checked property to identify which color is currently selected. –The Shortcut property can be used to define a keyboard combination that can be pressed to select the menu item.

37 MenuItem Control (Continued) For MenuItem objects displayed in a Multiple Document Interface (MDI) application, you can use the MergeMenu method to merge the menus of an MDI parent for with that of its child forms to create a consolidated menu structure. Because a MenuItem cannot be reused in multiple locations at the same time, such as in a MainMenu and a ContextMenu, you can use the CloneMenu method to create a copy of a MenuItem for use in another location. The Popup event enables you to perform tasks before a menu is displayed. For example, you can create an event handler for this event to display or hide menu items based on the state of your code. The Select event enables you to perform tasks such as providing detailed help for your application's menu items when the user places the mouse cursor over a menu item.

38 TreeView TreeView Control –Displays nodes hierarchically –Nodes Objects that contain values –Parent node »Contains child nodes »Can be expanded or collapsed –Root node »First parent node of a tree –Sibling nodes »Have same parent node –Child nodes »Can have child nodes of their own

39 TreeView

40 TreeView properties and events.

41 TreeView TreeNode properties and methods.

42 TreeView

43

44

45 TreeView Control

46 Public Class TreeView Inherits Control Displays a hierarchical collection of labeled items, each represented by a TreeNode. The Nodes collection holds all the TreeNode objects that are assigned to the TreeView control. 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. Because each TreeNode can contain a collection of other TreeNode objects, you might find it difficult to determine your location in the tree structure when you iterate through the collection. You can parse the TreeNode.FullPath string by using the PathSeparator string value to determine where a TreeNode label begins and ends.

47 TreeView Control (continued) You can display images next to the tree nodes by assigning an ImageList object to the ImageList property, and referencing the index value of an Image in the ImageList to assign that Image. Set the ImageIndex property to the index value of the Image that you want to display when a tree node is not selected. Likewise, set the SelectedImageIndex property to the index value of the Image that you want to display when a tree node is selected. The images referenced by the ImageIndex and SelectedImageIndex property values are the default images displayed by all the tree nodes that are assigned to the Nodes collection. Each tree node can override the default images by setting the TreeNode.ImageIndex and TreeNode.SelectedImageIndex properties.

48 TreeView Control (continued) Tree nodes can be expanded to display the next level of child tree nodes. The user can expand the TreeNode by clicking the plus-sign (+) button, if one is displayed next to the TreeNode, or you can expand the TreeNode by calling the TreeNode.Expand method. To expand all the child tree node levels in the Nodes collection, call the ExpandAll method. You can collapse the child TreeNode level by calling the TreeNode.Collapse method, or the user can press the minus- sign (-) button, if one is displayed next to the TreeNode. You can also call the TreeNode.Toggle method to alternate between the expanded and collapsed states.

49 TreeView Control (continued) Tree nodes can optionally display check boxes. To display the check boxes, set the CheckBoxes property of the TreeView to true. The Checked property is set to true for tree nodes that are in a checked state. Note Setting the TreeNode.Checked property from within the BeforeCheck or AfterCheck event causes the event to be raised multiple times and can result in unexpected behavior. For example, you might set the Checked property in the event handler when you are recursively updating the child nodes, so the user does not have to expand and check each one individually.

50 TreeView Control (continued) To prevent the event from being raised multiple times, add logic to your event handler that only executes your recursive code if the Action property of the TreeViewEventArgs is not set to TreeViewAction.Unknown. For an example of how to do this, see the Example section of the AfterCheck or BeforeCheck events. You can change the appearance of the TreeView control by setting some of its display and style properties. Setting ShowPlusMinus to true displays a plus-sign or minus- sign button next to each TreeNode object that can be expanded or collapsed, respectively. Setting the ShowRootLines property to true causes the TreeView to display lines that join all the root tree nodes together. You can display lines that connect child tree nodes to their root node by setting the ShowLines property to true.

51 TreeView Control (continued) Setting the HotTracking property to true changes the appearance of the tree node labels as the mouse pointer passes over them. When hot-tracked, the tree node labels take on the appearance of a hyperlink. Note When setting the CheckBoxes, Scrollable, ImageIndex, and SelectedImageIndex properties at run time, the TreeView handle is recreated (see Control.RecreateHandle) to update the control's appearance. This causes all tree nodes to be collapsed, with the exception of the selected TreeNode.

52 TreeNode Class

53 Public Class TreeNode Inherits MarshalByRefObject Implements ICloneable, ISerializable The Nodes collection holds all the child TreeNode objects assigned to the current TreeNode. You can add, remove, or clone a TreeNode; when doing so, all child tree nodes are added, removed, or cloned. Each TreeNode can contain a collection of other TreeNode objects. This can make it difficult to determine where you are in the TreeView when iterating through the collection. To determine your location in a tree structure, use the FullPath property. The FullPath string can be parsed using the PathSeparator string value to determine where a TreeNode label begins and ends.

54 TreeNode Class The TreeNode label is set by setting the Text property explicitly. The alternative is to create the tree node using one of the TreeNode constructors that has a string parameter that represents the Text property. The label is displayed next to the TreeNode image, if one is displayed. To display images next to the tree nodes, assign an ImageList to the ImageList property of the parent TreeView control and assign an Image by referencing its index value in the ImageList property. Set the ImageIndex property to the index value of the Image you want to display when the TreeNode is in an unselected state. Likewise, set the SelectedImageIndex property to the index value of the Image you want to display when the TreeNode is selected.

55 TreeNode Class Selecting specific tree nodes and iterating through the Nodes collection can be achieved by using the following property values: FirstNode, LastNode, NextNode, PrevNode, NextVisibleNode, PrevVisibleNode. Assign the TreeNode object returned by one of aforementioned properties to the TreeView.SelectedNode property to select that tree node in the TreeView control. Tree nodes can be expanded to display the next level of child tree nodes. The user can expand the TreeNode by pressing the plus (+) button next to the TreeNode, if one is displayed, or you can expand the TreeNode by calling the Expand method. To expand all child tree node levels in the Nodes collection, call the ExpandAll method.

56 TreeNode Class You can collapse the child TreeNode level by calling the Collapse method, or the user can press the minus (-) button next to the TreeNode, if one is displayed. You can also call the Toggle method to alternate the TreeNode between the expanded and collapsed states. Tree nodes can optionally display a check box. To display the check boxes, set the CheckBoxes property of the TreeView to true. The Checked property is set to true for tree nodes that are in a checked state.

57 Control Tester Homework Assignment

58 PictureBoxes –Display images Bitmap GIF (Graphics Interchange Format) JPEG (Joint Photographic Expert Group) Metafile –Image property Image to be displayed

59 PictureBoxes PictureBox properties and events.

60 PictureBox Class

61 Public Class PictureBox Inherits Control Typically the PictureBox is used to display graphics from a bitmap, metafile, icon, JPEG, GIF or PNG file. Set the Image property to the Image you want to display, either at design time or at run time. Clipping and positioning of the image in the display area is controlled by the SizeMode property which is set to values in the PictureBoxSizeMode enumeration. You can change the size of the display area at run time with the ClientSize property. The PictureBox control is displayed by default without any borders. You can provide a standard or three-dimensional border using the BorderStyle property to distinguish the picture box from the rest of the form, even if it contains no image.

62 Control Tester Homework Assignment


Download ppt "Some Interesting Controls. Controls We've UsedNew Controls LabelListBox TextBoxCheckedListBox ComboBoxTabControl ButtonTabPage Menu MenuItem TreeView."

Similar presentations


Ads by Google