Question

I'm trying to understand what do I have to do to override the behavior of the ToolStripDropDown control on System.Windows.Forms where if you use this constructor:

 var button = new ToolStripSplitButton("text","path to image", clickEventHandler)

then the drop down will only show if I keep the mouse pressed and if I use this other

var button = new ToolStripSplitButton("text","path to image")

then the drop down will show when I click.

It is clear to me that supplying a click event handler is very explicit in saying "hey, when I click, execute this" but in the case of a ToolStripSplitButton the distinction blurs a bit because of the split nature of the control itself.

So, what I like to do is a) When the user clicks on the button part of the ToolStripSplitButton, the click event handler executes as normal b) When I click OR press the mouse on the arrow part of the ToolStripSplitButton then the drop down shows

Is there any OOB property/method to do just this?

Thanks

Was it helpful?

Solution

The ToolStripSplitButton has two click handlers. One is called "Click" and the other is called "ButtonClick". The one from the constructor is the "Click" handler and fires no matter where on the control you click. The "ButtonClick" handler only fires when you click the button itself, not the arrow.

Try this:

var button = new ToolStripSplitButton("text","path to image");
button.ButtonClick += clickEventHandler;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top