dotnetmonitor.com |
|
||||||||||||
| Nope, 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 with, end with or contain adjacent separators. bool itemDisplayed = false; ToolStripItem lastSeparator = null;
foreach (ToolStripItem tsItem in tsItems) { if (tsItem.Available) { if (tsItem is ToolStripSeparator) { // hide all separators tsItem.Visible = false; // only set in a separator that has a chance to be shown later // if no items have been displayed, no chance if (itemDisplayed) lastSeparator = tsItem; } else if (lastSeparator != null) { // show it when valid lastSeparator.Visible = true; } else { itemDisplayed = true; } } } } |
||||||||||||
|
||||||||||||