some interesting controls. controls we've usednew controls labellistbox textboxcheckedlistbox...

62
Some Interesting Controls

Upload: coral-lindsey

Post on 01-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

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

Some Interesting Controls

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

Some Interesting Controls

Controls We've Used New Controls

Label ListBox

TextBox CheckedListBox

ComboBox TabControl

Button TabPage

Menu

MenuItem

TreeView

TreeNode

PictureBox

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

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

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

ListBoxes and CheckedListBoxes

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

ListBoxesListBox properties, methods and events

Description / Delegate and Event Arguments

Common Properties

Items The collection of items in the ListBox.

MultiColumn Indicates whether the ListBox can break a list into multiple columns. Multiple columns eliminate vertical scrollbars from the display.

SelectedIndex Returns the index of the selected item. If the user selects multiple items, this property arbitrarily returns one of the selected indices; if no items have been selected, the property returns -1.

SelectedIndices Returns a collection containing the indices for all selected items.

SelectedItem Returns a reference to the selected item (if multiple items are selected, it returns the item with the lowest index number).

SelectedItems Returns a collection of the selected item(s).

SelectionMode Determines the number of items that can be selected, and the means through which multiple items can be selected. Values None, One, MultiSimple (multiple selection allowed) or MultiExtended (multiple selection allowed using a combination of arrow keys or mouse clicks and Shift and Control keys).

Sorted Indicates whether items are sorted alphabetically. Setting this property’s value to True sorts the items. The default value is False.

Common Method

GetSelected Takes an index as an argument, and returns True if the corresponding item is selected.

Common Event (Delegate EventHandler, event arguments EventArgs)

SelectedIndexChanged

Generated when selected index changes. This is the default event when the control is double-clicked in the designer.

ListBox properties, methods and events

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

ListBoxes

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

ListBoxes

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

ListBoxes

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

CheckedListBoxesCheckedListBox properties, methods and events

Description / Delegate and Event Arguments

Common Properties (All the ListBox properties and events are inherited by CheckedListBox.)

CheckedItems Contains the collection of items that are checked. This is distinct from the selected item, which is highlighted (but not necessarily checked). [Note: There can be at most one selected item at any given time.]

CheckedIndices Returns indices for all checked items. This is not the same as the selected index.

SelectionMode Determines how many items can be checked. Only possible values are One (allows multiple checks to be placed) or None (does not allow any checks to be placed).

Common Method

GetItemChecked Takes an index and returns True if the corresponding item is checked.

Common Event (Delegate ItemCheckEventHandler, event arguments ItemCheckEventArgs)

ItemCheck Generated when an item is checked or unchecked.

ItemCheckEventArgs Properties

CurrentValue Indicates whether the current item is checked or unchecked. Possible values are Checked, Unchecked and Indeterminate.

Index Returns index of the item that changed.

NewValue Specifies the new state of the item.

CheckedListBox properties, methods and events.

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

CheckedListBox

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

ListBox

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

ListBox ControlPublic 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.

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

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.

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

CheckedListBox Control

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

CheckedListBox ControlPublic 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.

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

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

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

Tab Control

• TabControl– Creates tabbed windows– Saves space using TabPage objects

• TabPage objects– Similar to Panels and GroupBoxes– Can contain controls

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

Tab Control

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

Tab Control

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

Tab Control

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

Tab Control

TabControl properties and events

Description / Delegate and Event Arguments

Common Properties

ImageList Specifies images to be displayed on tabs.

ItemSize Specifies tab size.

MultiLine Indicates whether multiple rows of tabs can be displayed.

SelectedIndex Index of selected TabPage.

SelectedTab The selected TabPage.

TabCount Returns the number of tab pages.

TabPages Collection of TabPages within the TabControl.

Common Event (Delegate EventHandler, event arguments EventArgs)

SelectedIndexChanged Generated when SelectedIndex changes (i.e., another TabPage is selected).

TabControl properties and events.

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

Tab Control

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

TabControl

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

TabControlPublic 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.

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

TabPage Control

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

TabPage ControlPublic 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.

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

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

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

Menus

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

Menus

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

Menus

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

MenusMainMenu and

MenuItem events and properties

Description / Delegate and Event Arguments

MainMenu Properties

MenuItems Lists the MenuItems that are contained in the MainMenu.

RightToLeft Causes text to display from right to left. Useful for languages, such as Arabic, that are read from right to left.

MenuItem Properties

Checked Indicates whether a menu item is checked (according to property RadioCheck). Default value is False, meaning that the menu item is unchecked.

Index Specifies an item’s position in its parent menu. A value of 0 places the MenuItem at the beginning of the menu.

MenuItems Lists the submenu items for a particular menu item.

RadioCheck Specifies whether a selected menu item appears as a radio button (black circle) or as a checkmark. True displays a radio button, and False displays a checkmark; default False.

Shortcut Specifies the shortcut key for the menu item (e.g., Ctrl + F9 is equivalent to clicking a specific item).

ShowShortcut Indicates whether a shortcut key is shown beside menu item text. Default is True, which displays the shortcut key.

Text Specifies the menu item’s text. To create an Alt access shortcut, precede a character with & (e.g., &File for File).

Common Event (Delegate EventHandler, event arguments EventArgs)

Click Generated when item is clicked or shortcut key is used. This is the default event when the menu is double-clicked in designer.

MainMenu and MenuItem properties and events.

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

MainMenu Class

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

MainMenu Class 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.

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

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.

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

MenuItem Control

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

MenuItem Control 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.

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

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.

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

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

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

TreeView

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

TreeView

TreeView properties and events

Description / Delegate and Event Arguments

Common Properties

CheckBoxes Indicates whether checkboxes appear next to nodes. A value of True displays checkboxes. The default value is False.

ImageList Specifies the ImageList containing the node icons. An ImageList is a collection that contains Image objects.

Nodes Lists the collection of TreeNodes in the control. Contains methods Add (adds a TreeNode object), Clear (deletes the entire collection) and Remove (deletes a specific node). Removing a parent node deletes all its children.

SelectedNode The selected node.

Common Event (Delegate TreeViewEventHandler, event arguments -TreeViewEventArgs)

AfterSelect Generated after selected node changes. This is the default event when the control is double-clicked in the designer.

TreeView properties and events.

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

TreeViewTreeNode properties and methods

Description / Delegate and Event Arguments

Common Properties

Checked Indicates whether the TreeNode is checked (CheckBoxes property must be set to True in parent TreeView).

FirstNode Specifies the first node in the Nodes collection (i.e., first child in tree).

FullPath Indicates the path of the node, starting at the root of the tree.

ImageIndex Specifies the index of the image shown when the node is deselected.

LastNode Specifies the last node in the Nodes collection (i.e., last child in tree).

NextNode Next sibling node.

Nodes The collection of TreeNodes contained in the current node (i.e., all the children of the current node). Contains methods Add (adds a TreeNode object), Clear (deletes the entire collection) and Remove (deletes a specific node). Removing a parent node deletes all its children.

PrevNode Indicates the previous sibling node.

SelectedImageIndex Specifies the index of the image to use when the node is selected.

Text Specifies the TreeView’s text.

Common Methods

Collapse Collapses a node.

Expand Expands a node.

ExpandAll Expands all the children of a node.

GetNodeCount Returns the number of child nodes.

TreeNode properties and methods.

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

TreeView

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

TreeView

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

TreeView

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

TreeView Control

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

TreeView ControlPublic 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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

TreeNode Class

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

TreeNode Class 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.

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

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.

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

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.

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

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.

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

Control TesterHomework Assignment

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

PictureBoxes

• PictureBoxes– Display images

• Bitmap

• GIF (Graphics Interchange Format)

• JPEG (Joint Photographic Expert Group)

• Metafile

– Image property• Image to be displayed

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

PictureBoxesPictureBox properties and events

Description / Delegate and Event Arguments

Common Properties

Image Sets the image to display in the PictureBox.

SizeMode Enumeration that controls image sizing and positioning. Values are Normal (default), StretchImage, AutoSize and CenterImage. Normal places image in top-left corner of PictureBox, and CenterImage puts image in middle (both cut image off if it is too large). StretchImage resizes image to fit in PictureBox. AutoSize resizes PictureBox to hold image.

Common Events (Delegate EventHandler, event arguments EventArgs)

Click Raised when user clicks the control. Default event when this control is double clicked in the designer.

PictureBox properties and events.

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

PictureBox Class

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

PictureBox ClassPublic 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.

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

Control TesterHomework Assignment