4

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

Román
  • 1,943
  • 2
  • 18
  • 28
  • Hard to figure out what you mean. A ToolStripSplitButton already behaves the way you want to. Sounds to me like you are confuzzling the behavior of ToolStripDrownDownButton. You need to assign event handlers to the items in the dropdown separately. – Hans Passant Feb 03 '11 at 12:53
  • @Hans: I had originally posted the same comment, but it looks like it really does change the behavior of the `ToolStripSplitButton` if you assign a click event handler in the constructor. The click event handler is triggered even if you click the drop-down arrow. – Cody Gray - on strike Feb 03 '11 at 13:10

1 Answers1

11

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;
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
msergeant
  • 4,771
  • 3
  • 25
  • 26