Sunday 8 May 2011

Menus and ToolBar Control using C#

Menus and ToolBar Controls
 In this category following controls comes-
    MenuStrip
    ToolStrip controls
    ContextMenusStrip
    StatusStrip





MenuStrip Control
Useful properties

   AllowItemReorder (Inherited from ToolStrip) - Gets or sets a value indicating whether drag-and-drop and item reordering are handled privately by the MenuStrip class. Set the property to true to allow reordering. At run time, the user holds down the ALT key and the left mouse button to drag a ToolStripMenuItem to a different location on the MenuStrip.

   AllowMerge (Inherited from ToolStrip) - When enabled, this property allows multiple-document interface (MDI) children to combine their respective menus in the MDI parent.

   Dock - Gets or sets which edge of the parent container a MenuStrip is docked to.

   LayoutStyle - Gets or sets a value indicating how the MenuStrip lays out its items.

   Padding (Inherited from Control) - Gets or sets the control's internal spacing characteristics. The default values for Padding are reasonably close to Windows user interface guidelines.

   RenderMode - Gets or sets the painting styles to be applied to the MenuStrip.

   TextDirection (Inherited from ToolStrip) - Allows the text to be rotated within the button. The property takes one of four values contained in the ToolStripTextDirection enumeration.
       Horizontal - Specifies horizontal text orientation.
       Inherit - Specifies that the text direction is inherited from the parent control. (Default state)
       Vertical270 - Specifies that text is to be rotated 270 degrees clockwise.
       Vertical90 - Specifies that text is to be rotated 90 degrees clockwise.

ToolStrip Control
    The ToolStrip is a container for holding different types of controls that are derived from ToolStripItem. In the example that we just created, the ToolStrip holds a selection of buttons which are instances of ToolStripButton. Other items that can be held within the ToolStrip are:
      ToolStripSplitButton
      ToolStripDropDownButton
      ToolStripLabel
      ToolStripProgressBar
      ToolStripSeparator
      ToolStripComboBox
      ToolStripTextBox
A ToolStrip appears by default as Office-style with a flat look. Windows XP themes are supported  however the painting of the control may be overridden.
Adding standard Items in ToolStrip-


ContextMenusStrip Control-
 
   Applications use two kinds of menus—main menus and context menus. Context menus are "pop up" menus that provide additional options, usually when the user right-clicks a part of the window.
Adding Menus in ContextMenusStrip
                             

   At runtime, your ContextMenusStrip won’t appear. You have two choices to display it. The easiest approach is to associate it with another control by setting the Control.ContextMenuStrip property to your ContextMenusStrip object. When the user right-clicks the control, your context menu appears automatically. As shown in Picture.

1 comment: