Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

Browse by Tags

All Tags » ToolStrip (RSS)


  • How can I bind a list of items to entries in a ToolStripDropDown?

    Several people have asked on the newsgroups about a good method to bind a list of items to entries in a ToolStripDropDown instance. I've run into this issue a couple of times and wanted to share some sample code. The class takes in a ToolStripDropDown...
  • How can I reset the settings?

    The sample code below will do that – it simply uses a named set of settings that captures the state before any custom settings are applied. Then, with button click or whatever you can apply the custom set. private void Form1_Load(object sender, EventArgs...
  • How do I programatically move ToolStrips within or across ToolStripPanels?

    Within a ToolStrip: Simply set the ToolStrip Location property. Across ToolStrips: Either add the ToolStrip to the ToolStripPanel's Controls collection or use Join(ToolStrip). NOTE: Join() simulates the drop operation of a ToolStrip and is order dependent...
  • How can I use the ToolStripPanel with MDI applications?

    The following is how to use ToolStripPanels correctly in an MDIParent. This is important, because due to layering and MDI limiations, use of ToolStripContainer doesn't work well. public Form1() { // Make Form MDI Parent this.IsMdiContainer = true;...
  • Why does the ToolStripContainer not support MDI?

    ToolStripContainer does not support MDI properly because, like any dock filled container, it would be layered above the MDI child container that is part of the MDI parent. To workaround this, use ToolStripPanel – see that section for a code example.
  • What is the ToolStripContainer?

    ToolStrip container is a composite control very similar in overall design to the SplitContainer. It takes four ToolStripPanels docked to the sides and one ContentPanel dock filled in the middle to make up the typical four sided arrangment commonly used...
  • How can I disable Visual Styles?

    The System Renderer renders ToolStrips similar to Win32 look and feel. You can use with or without VisualStyles by ToolStripManager.VisualStylesEnabled = false;
  • How can I get the Office look and feel to have straight ends?

    Set RoundedEdges = false. You may also have to override OnRendererToolStripBorder and not call base. ((ToolStripProfessionalRenderer)ToolStripManager.Renderer).RoundedEdges = false;
  • How can I change text color on selection?

    Below is an example of changing text color on selection within a custom renderer: protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) { if (e.Item.Selected) { e.TextColor = Color.Gold; } else { e.Item.ForeColor = Color.White;...
  • What is the ConnectedArea?

    Connected area is that little bit of the dropdown for a menu where the border is discontinuous. Below is an examples of how to access and paint that. protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { using (Brush b = new SolidBrush...
  • How do I change the ProfessionalColorTable?

    Override ProfessionalColorTable and change only the colors you care about. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load Dim t As MyColorTable = New MyColorTable ToolStrip1.Renderer = New ToolStripProfessionalRenderer...
  • What order do the ToolStrip Renderer events come in?

    Generally its this - background, item background, item foregound effects, toolstrip border. OnRenderToolStripBackground OnRender[Label|Button|MenuItem...]Background OnRenderItemText OnRenderItemArrow OnRenderItemImage OnRenderToolStripBorder The toolstrip...
  • When should I use a renderer and when should I just override OnPaint

    Use draw from custom ToolStrip handler – which is the entry point into Renderer code. OnRender* will be called as a result. To change Renderer behavior, override OnRender*. public class MyLabel : ToolStripLabel{ protected override void OnPaint(PaintEventArgs...
  • Can I make the ProfessionalRenderer look like the old Office?

    Yes... Create a class which overrides the ToolStripProfessionalRenderer called OldProfessionalRenderer Pass in a new ProfessionalColorTable with professionalColorTable.UseSystemColors = false; In the OldProfessionalRenderer class, override the following...
  • How do I turn off the "Office" colors?

    For one ToolStrip ProfessionalColorTable colorTable = new ProfessionalColorTable(); colorTable.UseSystemColors = true; toolStrip.Renderer = new ToolStripProfessionalRenderer(colorTable); For the entire app: ToolStripManager.VisualStylesEnabled = false;
  • How do I globally change the painting (Renderer) for all my ToolStrips?

    Use RenderMode to pick between stock renderers. Use ToolStrip.Renderer to assign a custom renderer. Ensure that RenderMode == ManagerRenderMode (default) class Form6 : Form { ComboBox targetComboBox = new ComboBox(); public Form6() { // alter renderer...
  • How do Settings work with the ToolStripManager?

    Settings are another feature handled in ToolStripManager. This uses the settings engine to automatically persist and restore the entire ToolStrip tree. This allows you to enable drag to dock scenarios in the ToolStripPanel and AllowItemReorder without...
  • How does Merging work with the ToolStripManager?

    ToolStripMerging is driven through two different mechanisms: Automatic (MDI) and manual. This section covers top level concepts in both of the mechanisms. The rules of how the items merge do not change for these two methods, just the triggering mechanism...
  • What is the ToolStripManager?

    ToolStripManager is a static class that handles application wide ToolStrip related tasks such as merging, settings and renderer exposure.
  • How can I use a ToolStripDropDown as a Tree-View dropdown?

    This is a rather spiffy article: http://blogs.msdn.com/jfoscoding/archive/2005/03/03/384430.aspx
  • Can I show animated images in ToolStrips?

    Yes. ToolStrip supports the ImageAnimator class - if you assign an Animated GIF to the Image property it will automatically render the animation.
  • How does Overflow work with the ToolStrip?

    To be precise, overflow is a feature of the ToolStrip's default LayoutStyle (StackWithOverflow), not of the ToolStrip control itself. You determine what overflow action is preferred via the Overflow property (Always, Never, AsNeeded). To determine...
  • How can I synchronize a ToolStripSplitButton's item with the selection?

    ToolStripSplitButton.DefaultItem is an easy mechanism to synchronize the click event from the ToolStripSplitButton's item chosen from the dropdown with the one rendered in the button area. This sample assumes you have a click handler associated with...
  • How can I populate a ToolStripDropDownItem?

    ToolStripDropDownItem is the abstract base class for ToolStripMenuItem, ToolStripDropDownButton, ToolStripSplitButton and provides the API around populating and synching the dropdown and items within it. This class implements all the dropdown plumbing...
  • How can I add a User Control to a ToolStrip?

    ToolStripControlHost is the base class for our ToolStripTextBox, ToolStripComboBox, ToolStripProgressBar, and can wrap any user control to be hosted in the ToolStrip. There are multiple ways to use ToolStripControlHost:: Inherit from ToolStripControlHost...
  • Do ToolStrips automatically eliminate duplicate or trailing separators from layout?

    No, but the following code will do it for you: void DropDown_Layout(object sender, LayoutEventArgs e) { StripSeparators(((ToolStrip)sender).Items); } public void StripSeparators(ToolStripItemCollection tsItems) { // ItemCollections should neither begin...
  • What's an easier way to enter a separator than newing one up or picking from the dropdown?

    Simply enter a hyphen or dash("-") in either the designer template node or via the Add method on ToolStripItemCollection. This will automatically create a separator.
  • How do I get toggle button?

    toolStripButton.CheckOnClick = true; toolStripButton.CheckedChanged += new EventHandler(toolStripButton_CheckedChanged);
  • Do ToolStrips support a link control?

    Yes, ToolStripLabel has an IsLink property that will render it in a link style. LinkColor, LinkVisited and LinkBehavior are exposed.
  • How do I get a mnemonic for a ToolStripComboBox, ToolStripTextBox or similar?

    ToolStripLabel supports mnemonic forwarding – simply precede your ToolStripControlHostItem with a ToolStripLabel with a mnemonic defined and you will get focus to the ToolStripControlHostItem when ALT+mnemonic is pressed.
  • How can I clone a ToolStripMenuItem?

    By default, ToolStripMenuItem does not contain an implementation for clone. Here's the code for ToolStripMenuItem.Clone. An alternate solution is to implement IBindableComponent and databind your menu item to a Command which drives the Text/Image...
  • How can I tell when the mouse is over a  ToolStripButton?

    Use the Selected property for items in which "CanSelect" is true. Otherwise you'll have to sync MouseEnter, MouseLeave events. You can check for Selected in your custom Renderer as well.
  • How do I change layout characteristics not dircectly exposed in ToolStrip?

    You access the LayoutSettings object offered at the ToolStripLevel and cast to the appropriate type and access the properties there. The following is an example of changing the flow direction of a ToolStrip. toolStrip1.LayoutStyle = ToolStripLayoutStyle...
  • How does the ToolStrip Layout work?

    By default the ToolStrip control utilizes a StackWithOverflow layout that supports overflow and item alignment. Stack refers to how the items are laid out within the ToolStrip, each item stacked aside each other at both ends of the ToolStrip. ToolStripLayoutStyle...
  • How can I add a customization dialog like the one in Office?

    A common customer request we get is a dialog similar to Office's to handle end user customization to choose items. We don't include this in the product. However, we do have a great sample on this already created, and the API around ToolStrips...
  • How can I customize the ToolStripItems at design-time?

    The two avenues of customization covered here are custom ToolStripItems at design time and custom renderer custom ToolStrips at design time. Custom ToolStripItems Custom ToolStripItems can be created by extending existing ToolStripItems like ToolStripButton...
  • How do I get one image out of many to not be scaled?

    Use ToolStripItem.ImageScaling = ToolStrimItemImageScaling.None
  • How does image scaling work with ToolStrips?

    Image scaling is determined by the interaction of several properties. size ToolStrip.ImageScalingSize This is a the size that will be used to scale into as determined by the Item's ImageScaling and the container's AutoSize setting ToolStripItemImageScaling...
  • How do property values flow from parent to auto created dropdowns?

    For the implementation of faux-ambient properties we make a distinction in how the dropdown for a ToolStripDropDownItem is created. We automatically flow Font, ImageScalingSize and Renderer to the autocreated dropdown. In the case of explicitly created...
  • How can I tab out of a ToolStrip? It just starts over from the first item again and again.

    In this case, the ToolStrip will accept the first tab to tab in - and the arrow keys will do wrapping selection. The second tab will tab you to the next control. Commonly used when not contained within a ToolStripPanel. toolStrip.TabStop = true;
  • How do Mnemonics work with ToolStrips?

    Combined with or following the ALT key, mnemonics are one way to activate a ToolStripItem via keyboard. ToolStrip supports both explicit and implicit mnemonics. Explicit mnemonics are defined inline with the ampersand (&) character preceding the letter...
  • How does ToolStrip usage affect Tab order?

    Toolstrips have three main usage patterns that impact how they are laid out, keyboard interaction and end-user behavior. Joined in a ToolStripPanel This means that the ToolStrip is typically repositionable within the ToolStripPanel and across ToolStripPanels...
  • Why are ToolStrips limited under Partial Trust?

    The limitations of ToolStrips under partial trust are designed primarily to prevent spoofing attacks. Spoofing attacks consist of some fake dialog or familiar window that lures the user into entering personal information. The two elements are a full fidelity...
  • How does parenting work with ToolStrip controls?

    The concept of container ownership and parenting is more complex in ToolStrips than in a typical Windows Forms container control. That is necessary to support dynamic scenarios such as overflow, sharing drop downs across multiple ToolStrip items and to...
  • Do I need to worry about double buffering?

    By default the ToolStrip is double buffered; taking advantage of the OptimizedDoubleBuffer API offered in Windows Forms 2.0.
  • When should I use Paint/OnPaint and when should I override the ToolStripRenderer?

    If you want to tweak a few aspects of how an item is painted, overriding the ToolStripRenderer might be the right idea. If you are writing a new item and want to control all aspects of the painting, overriding OnPaint will give you total control. From...
  • How can I customize the painting of ToolStrip controls?

    There are several ways to achieve custom painting with the ToolStrip API. As with other System.Windows.Forms.Controls, the ToolStrip and ToolStripItem both have overridable OnPaint methods and Paint events. As with regular painting, the coordinate system...
  • Is the '&' shortcut character broken in some ToolStripMenuItems?

    I have tried to use the '&' (ampersand) character to declare the Alt shortcut in ToolStripMenuItem.Text but it doesn't work. Is there another kind of declaration? In fact it works when I add the ToolStripMenuItem to a MenuStrip.Items but...
  • Can a ToolStripMenuItem be used in multiple menus?

    Is it possible to have the same items in two different MenuStrip controls, for example the main menu and a context menu? With the entire ToolStrip family of controls we do not have an integrated commanding architecture nor do we support cloning of items...
  • What replaces the Popup event for ContextMenuStrip?

    If the ContextMenuStrip has to replace the ContextMenu control, I'm missing something behind the scenes, because I can't find the Popup event. Is there any other event I can use in its behalf? I think you're looking for the Opening and Opened...
  • How do I create a ToolStrip with the normal Windows system colors, not the blue theme?

    When I make a menu bar, I get a blue background theme. How can I make it the normal Windows menu bar, i.e., grey? You can change any strip control's ToolStrip.RenderMode to System to get system look and feel.
  • How do I disable moving ToolStrips?

    Set the ToolStrip.GripStyle property to Hidden.


Page view counter