dotnetmonitor.com

 
Index
Previous
Next

 

This item renders very similarly to the ToolStripDropDownButton and combines a button side and a dropdown arrow side. You have full button API combined with DropDown button functionality.

DefaultItem

ToolStripSplitButton.DefaultItem is an easy mechanism to synchronize the click event from the ToolStripSplitButtons item chosen from the dropdown with the one rendered in the button area. This sample assumes you have a click handler associated with each item in the dropdown and have set a default item as part of initialilization.

 

ToolStripSplitButton veggieButton = new ToolStripSplitButton("Veggies");

veggieButton.DropDownItems.Add("Asparagus");

veggieButton.DropDownItems.Add("Bok Choy");

veggieButton.DropDownItems.Add("Cauliflower");

 

veggieButton.DisplayStyle = ToolStripItemDisplayStyle.Text;

veggieButton.DropDownItemClicked += new ToolStripItemClickedEventHandler(veggieButton_DropDownItemClicked);

veggieButton.DefaultItemChanged += new EventHandler(veggieButton_DefaultItemChanged);

// menustrip

ToolStrip ts = new ToolStrip();

ts.Items.Add(veggieButton);

this.Controls.Add(ts);

}

 

void veggieButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)

{

((ToolStripSplitButton)sender).DefaultItem = e.ClickedItem;

((ToolStripSplitButton)sender).Text = e.ClickedItem.Text;

}

Painting
When should I use Paint/OnPaint and when should I override the ToolStripRenderer?
Do I need to worry about double buffering?
Parenting
Partial Trust
Usage