What is the difference between menustrip and toolstrip




















The ToolStrip is like other controls, in that it is placed by the Location property, has a fixed size, and typically participates in the tab order. Combined with or following the ALT key, access keys are one way to activate a control using the keyboard. ToolStrip supports both explicit and implicit access keys.

Implicit definition uses an algorithm that attempts to find a matching item based on the order of characters in a given Text property. The shortcut keys used by a MenuStrip use a combination of the Keys enumeration which is not order-specific to define the shortcut key. You can also use the ShortcutKeyDisplayString property to display a shortcut key with text only, such as displaying "Del" instead of "Delete. A special algorithm handles navigation in the overflow region. When activated by the ALT key, the MenuStrip or ToolStrip typically neither take nor remove the focus from the control that currently has the focus.

If there is a control hosted within the MenuStrip or a drop-down of the MenuStrip , the control gains focus when the user presses the TAB key. In such cases, use the MenuActivate and MenuDeactivate events instead.

By default, CausesValidation is false. Call Validate explicitly on your form to perform validation. Stacking is the arranging of items beside each other at both ends of the ToolStrip. The following list describes the stack layouts. StackWithOverflow is the default.

This setting causes the ToolStrip to alter its layout automatically in accordance with the Orientation property to handle dragging and docking scenarios. Alignment determines the end of the ToolStrip to which the item is aligned. When items do not fit within the ToolStrip , an overflow button automatically appears. The Overflow property setting determines whether an item appears in the overflow area always, as needed, or never.

In the LayoutCompleted event, you can inspect the Placement property to determine whether an item was placed on the main ToolStrip , the overflow ToolStrip , or if it is not currently showing at all.

The typical reasons why an item is not displayed are that the item did not fit on the main ToolStrip and its Overflow property was set to Never. The other layout options are Flow and Table. It is similar to the FlowLayoutPanel. The features of Flow layout are as follows:. You can use the Dock and Anchor properties in code to align the items within the row. The Alignment property is ignored. In the LayoutCompleted event, you can inspect the Placement property to determine whether an item was placed on the main ToolStrip or did not fit.

The ToolStrip overflow button is not rendered, and Overflow is ignored. Table layout is the default for StatusStrip. It is similar to TableLayoutPanel. You can use the Dock and Anchor properties in code to align the items within the table cell. The following topics describe ToolStripItem and the controls that derive from it. ToolStripItem is the abstract base class for all the items that go into a ToolStrip. The following object model shows the ToolStripItem inheritance hierarchy.

The various container classes are designed to contain an appropriate subset of ToolStripItem controls. The following table lists the stock ToolStripItem controls and the containers in which they look best.

Although any ToolStrip item can be hosted in any ToolStrip -derived container, these items were designed to look best in the following containers:.

ToolStripDropDown does not appear in the designer toolbox. ToolStripButton is the button item for ToolStrip. You can display it with various border styles, and you can use it to represent and activate operational states. You can also define it to have the focus by default. The ToolStripLabel is like a ToolStripButton that does not get focus by default and that does not render as pushed or highlighted. ToolStripLabel as a hosted item supports access keys.

The ToolStripSeparator adds a vertical or horizontal line to a toolbar or menu, depending on the orientation. It provides grouping of or distinction between items, such as those on a menu. You can add a ToolStripSeparator at design time by choosing it from a drop-down list. However, you can also automatically create a ToolStripSeparator by typing a hyphen - in either the designer template node or in the Add method. ToolStripControlHost can host other controls, including custom controls, in two ways:.

To fully access the hosted control and properties, you must cast the Control property back to the actual class it represents. Extend ToolStripControlHost , and in the inherited class's parameterless constructor, call the base class constructor passing a class that derives from Control. This option lets you wrap common control methods and properties for easy access in a ToolStrip. A subset of the hosted control's properties and events are exposed at the ToolStripComboBox level, but the underlying ComboBox control is fully accessible through the ComboBox property.

A subset of the hosted control's properties and events are exposed at the ToolStripTextBox level, but the underlying TextBox control is fully accessible through the TextBox property. Vertical-StackWithOverFlow stacks items vertically and overflows as needed.

StackWithOverflow determines the stack model appropriate to the Dock property of the tool strip. Flow allows the items to stack horizontally or vertically as needed, and Table arranges all of the items flush left. Determines how the tool strip items are rendered. System uses system settings, Professional indicates a Microsoft Office -style appearance, and ManagerRenderMode gets the setting automatically.

When hosted in a ToolStripContainer , it indicates whether the tool strip will stretch to the full length of the ToolStripPanel. Note that the properties of the MenuStrip control are very similar to the properties of the ToolStrip control.

Because MenuStrip derives from ToolStrip, it exposes most of the same properties as the ToolStrip control and encapsulates most of the same functionality. ToolStripMenuItems provide all of the functionality that is expected of menus. Table explains some of the important properties of the ToolStripMenuItem control. Opened event. Delete lines setting the MenuItem. Shortcut property and reset these later in the designer, or edit the line to set the ToolStripMenuItem.

ShortcutKeys property using the Form. If the name of your MenuStrip is mainMenu , add the following line to the method: this. Add this. You may find errors.

If so, consult the class reference to resolve any remaining issues View your form in the designer. If all goes well, you will see your new menus. Readjust the layout to accommodate the different size of the new menu. Set any shortcut keys that were not edited in step All separators will appear as menu items containing a single hyphen. Right-click on these in the designer, select "Convert to" and replace with a real separator Compile your application and see if it runs!

ButtonSize , ToolStrip. DropDownArrows , or ToolStrip. Style Replace ToolStripButton. Pushed with ToolStripButton. Checked Replace ToolStrip. AddRange with ToolStrip. AddRange Use the designer to replace all the images for the buttons. The ImageList property still works, but it has been deprecated and cannot be used within the designer Cross your fingers, compile, and run Extending the ToolStrip and MenuStrip classes As I mentioned above, I wanted to change the behavior of these controls to create a user interface that was more intuitive.

They are: C. Copy Code. A list of licenses authors might use can be found here. Jim Hollenhorst Researcher. Neolisk Sep Jim Hollenhorst Sep Code Artist May Kobus du Bruyn Dec JamesParsons Nov Member May Jim Hollenhorst May Jim Hollenhorst 5-Apr Jim Hollenhorst 6-Apr Jim Hollenhorst Feb Jim Hollenhorst Jul Gareth Moore Feb Go to top.

Layout: fixed fluid. United States. First Prev Next. My vote of 5 NeonMika May Thanks, sitting here at work with your helping text is so much speeding-up this update :P. Thanks Neolisk Sep Worked perfectly, I was able to get from 50 errors down to 1 - and that one did not take long to fix. Overall converted my main menu in less than 1 hour.

Big thanks! Re: Thanks Jim Hollenhorst Sep Jim Hollenhorst. Your welcome! Great Job Code Artist May Thanks for solving the ToolStrip click through problem. Besides, I like the way you handle suppress highlighting. My vote of 5 micahtan 2-Mar Detailed, comprehensive, and useful. Thanks Kobus du Bruyn Dec Kobus du Bruyn. Your ClickThrough solution solved an irretating problem in my application. Many thanks, and an addition JamesParsons Nov Thanks Jim for this article, it made my upgrading straightforward, I just picked my way through your instructions.



0コメント

  • 1000 / 1000