<<

14.12.2016

Contents

 Menus Windows Programming  TreeView Using C#  TabControl

MenuStrip

2

Main Menus (mnu prefix)  Menus provide groups of related commands for Windows applications

 Main menu is the control that resides upper section of the form.

 It provides easy access for frequently used operations.

separator bars Checked menu item 3 4

Menu Design Standards Menus  Pulldown menus «MenuStrip» a way to select  New (Ctrl N)  Undo (Ctrl Z) commands and options  Open (Ctrl O)  Cut (Ctrl X)  Normally these are in a MenuStrip across the top of the application  Close  Copy (Ctrl C)  Begin by placing a MenuStrip across the  Save As  Paste (Ctrl V) application   Save (Ctrl S) Find (Ctrl F)  It displays boxes into which menu items and  Print (Ctrl P)  Replace (Ctrl H) cascading menus can be typed  Exit

5 6

1 14.12.2016

Adding Main Menu The MenuStrip Control  The MenuStrip control is essentially a ToolStrip control MainStrip is added to the form by dragging and dropping from. optimized for the display of ToolStripMenu items.  The MenuStrip control derives from ToolStrip and can host all the tool strip items described in the previous lesson. Its primary function, however, is to host ToolStripMenu items.  ToolStripMenuItem controls are the controls that provide the visual representation for items on a menu. They can appear as text, an image, or both and can execute code found in their ToolStripMenuItem

7 8

Menus The MenuStrip Control

PROPERTY DESCRIPTION  The type here text allows new items to be added AllowMerge Indicates whether this menu strip can be merged with another tool strip.  When you click on type LayoutStyle Indicates how the controls on the tool strip are laid out here a pull down appears ShowItemToolTips Indicates whether tool tips for individual tool strip items letting you select are displayed.  Menu item TextDirection Indicates the direction of the text in controls hosted in the tool strip.  ComboBox  Separator  TextBox

9 10

ToolStripMenuItem properties CREATING MENUS AND MENU ITEMS PROPERTY DESCRIPTION AutoSize Determines whether the menu item is automatically sized to fit the text.  To create an access shortcut (or keyboard Checked Determines whether the menu item appears as selected. CheckOnClick Determines whether the menu item is automatically shortcut), selected when clicked CheckState Returns the CheckState value of the menu item. CheckState can be Checked, Unchecked, or Indeterminate. DisplayStyle Determines how the tool strip menu item is displayed. DoubleClickEnabled Determines whether the DoubleClick event fires. DropDownItems Contains a collection of tool strip items (usually, but not necessarily, tool strip menu items) that appear in the drop-down list when this item is chosen.

11 12

2 14.12.2016

CREATING MENUS AND MENU ITEMS CREATING MENUS AND MENU ITEMS  To add other shortcut keys (e.g., -F9)

 To create an access shortcut (or keyboard shortcut),

13 14

Adding Separator Bars to Menus MenuStrip and ToolStripMenuItem an event.

Click Generated when an item is clicked or a  You can add a separator to any submenu shortcut key is used. This is the default event at design time by choosing Separator from when the menu is double clicked in the the drop-down box in the menu item designer design interface. DropDownOpened Occurs when Dropdown hasoOpened  Using “-”

15 Slide 16

Context Menus and the ContextMenuStrip Control  with ContextMenuStrip into Form

 All controls that can display a context menu expose a ContextMenuStrip property that represents the context menu associated with that control  A context menu is invoked when the user right-clicks a control.  You can set this property at design time in the Properties .

17 18

3 14.12.2016

Context Menu Context Menu  ContextMenuStrip menu  ContextMenu with ListBox menu item “Remove” ListBox

 ContextMenuStrip = ContextMenuStrip1

menu item

context menu

19 20

Context Menu Context Menu  Click menu item  Demo

Context Menu with user ListBox

21 22

The StatusBar Control The Control

 Alignment Property  Buttons Property  AutoSize Property  ButtonClick Event  BorderStyle Property  ImageList Property  Property  SendToBack() Method  Style Property  ShowToolTips Property  ToolTipText Property

23 24

4 14.12.2016

MenuItem Properties MenuItem

 Checked – if true displays check mark  Click – event which is raised when the  CheckOnClick – check state changes when menu item is clicked clicked   CheckState – one of Menu items are similar to buttons and are  CheckState.Checked handled in the same way  CheckState.Unchecked  CheckState.Indeterminate  ShortcutKeys – a member of the Shortcut enumeration indicating the shortcut key  * see MenuDemo

25 26

ComboBox Menu Items TreeView

 You can use a ComboBox as a menu item  Use the designer to add a set of Items to the  Presents a hierarchical of combo box the data  You can then select a value  Nodes can be  The click event is raised only when you click on  Selected the selected value, not when you change the  Expanded and collapsed selection  Text of nodes can be edited  If you have nothing selected, the selected item will be null  Nodes can be added or deleted programmatically

27 28

TreeNode TreeNode

 All nodes in the tree are instances of Text – the displayed text TreeNode Checked – true if the node is checked FullPath – the labels of all nodes from the  Constructors root to this node separated by “\\” TreeNode(string displayText) NextNode – returns next sibling  Properties PrevNode – returns previous sibling Nodes – get TreeNodeCollection of all  Methods children of this node Collapse – collapses the node

29 30

5 14.12.2016

TreeNode TreeView

Expand – expands the node  This is the actual control ExpandAll – expands all children of this  Properties node Nodes – get TreeNodeCollection of all GetNodeCount – returns the number of child children of this node nodes  – if true, displays checkboxes beside tree nodes SelectedNode – the selected node LabelEdit – if true, node text can be edited

31 32

TreeView MenuStript DEMO

 Events AfterSelect – after a node is selected AfterExpanded – after a node is expanded AfterCollapsed – after a node is collapsed AfterEdited – after a node is edited

33 34

6