<a href="http://www.micropoll.com/akira/mpview/585320-168921">Click Here for Poll</a><a href="http://www.questionpro.com" title="online surveys">Online Survey</a><BR> | <a href="http://www.micropoll.com" title="Website Polls">Website Polls</a><BR> | <BR><a href="http://www.micropoll.com/akira/MicroPoll?mode=html&id=168921">View MicroPoll</A></div>

Visual Studio 2010!

Read now >

Windows Mobile Development Thoughts

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.
ADVERTISEMENT
ADVERTISEMENT

 

DevSource.com: Your Source for Visual Studio on Facebook
ADVERTISEMENT
A Tour of ToolStrips in Windows Forms
By John Mueller

Rate This Article: Add This Article To:

A Tour of ToolStrips in Windows Forms - ' Not Your Father'
( Page 2 of 4 )

's Menu Bar">

Some developers wonder whether Microsoft's new ToolStrip control is actually a renamed ToolBar control, with a few extra features. The ToolStrip isn't a tempest in a teapot; it really is a great new control where you can create a flexible interface for application users.

Do you want to include a search function, right on the toolbar of your application? Using the ToolStrip control (a container for the other controls) makes the task incredibly easy. Unlike the old ToolBar, a ToolStrip can contain a host of controls, including ToolStripButton, ToolStripComboBox, ToolStripSplitButton, ToolStripLabel, ToolStripSeparator, ToolStripDropDownButton, and ToolStripTextBox.

However, the news doesn't actually stop with the ToolStrip control. It turns out that Microsoft has derived a number of interesting new controls from the ToolStrip control, including BindingNavigator, DataNavigator, MenuStrip, StatusStrip, and ToolStripDropDown. In short, many of the interesting new navigational aids in Visual Studio 2005 are related to the ToolStrip.

But don't let the automation get away from you. You'll still need to code.

Starting Simply

You're bound to use a MenuStrip at some point. In most cases, this is one of those controls that you can't build an application without. The MenuStrip control begins simply with the usual entries, shown in Figure 1. All I needed to do was select "Insert Standard Items" from the SmartTag to create this menu.

Figure 1: Don't assume the MenuStrip is like the MenuBar of old.

However, other than the convenience it offers, you might wonder how the MenuStrip improves on the MenuBar control of old. Look again at Figure 1 and you'll see the difference. Instead of typing a new menu entry into a MenuStrip, you can choose a ComboBox, Separator, or TextBox.

Consider the possibility of letting a user type a command into a menu instead of selecting a static option. For example, you could add a TextBox to the Help menu to permit a community help search, or to make a specific help desk request. You can use the TextBox in read-only mode to report results, or make the menu change based on specific criteria.

To control how the menu item works, and also provide several possibilities, you can use the ComboBox instead. Imagine having a Zoom menu where the zoom percentages appear in a ComboBox. Likewise, you can include a menu item for changing application colors, where the acceptable choices appear in the ComboBox. The idea is that you don't have to use the same static menus that you always have.

The new menu items have all kinds of interesting properties. For example, when you include a TextBox or ComboBox control in a menu, you can also provide entries for the AutoCompleteCustomSource property. Each AutoComplete item appears on a separate line. When a user types in a string, the control automatically looks for a potential AutoComplete option.

Speaking of AutoComplete, you don't have to settle for a static set of strings for the input. By selecting an option in the AutoCompleteSource property, you can use the file system, browser history, recently used file list, all URLs stored by the browser, or the file system directories as a source of AutoComplete entries. You can even define the method the control uses for making a suggestion. The control can automatically complete the input with the most-likely string value, display a list of values that could match the user input, or perform a combination of both.

My favorite feature is a new way of editing menus. Previously, it was a tad cumbersome to type the menu entries in the design area and then change each entry's properties in the Properties window. Yes, it works fine, and you can still use that technique, but it's easier to select Edit Items from the SmartTag to display the Items Collection Editor (shown in Figure 2). You enter all the menu items at a specific level on the left side, and configure them on the right. It really is faster and easier than using the old method. To go to the next level, select the item on the left, and click the ellipses in the DropDownItems property.

Figure 2: Use the Items Collection Editor to reduce the work required to add menu entries.



 
 
>>> More Using Microsoft Visual Studio Articles          >>> More By John Mueller