I’m using Windows Forms in C#.
I have a main form with a couple of toolbars that contain toolStripButtons. After working with another form that contains data, the main form loses focus and clicking on a toolStripButton does not trigger OnClick event: the first click activates the main form, and only the second click actually pushes the button. I need the user to click a button only once to trigger a Click event, any ideas on how to do that? Thanks.
Notes:
- I was using MDI and there were no problems clicking on the parent’s form buttons. But now the paramount is to have forms freely floating across multiple displays.
- The worker forms have the main form as the Owner property, this way they stay on top of the main form.
- When I click on the button of an inactive form, none of MouseHover, MouseEnter, MouseDown nor MouseUp fires. It’s just main form’s Activate event that fires.
- There is a treeView (inside a tabControl, inside a splitContainer, inside a panel), on the main form. Its items are selected upon a first mouse click, even if the main form is inactive. I guess not all controls are equal!
What you need to do is create a class that inherits
ToolStripand handles theWndProc. This is one way to do it. There are others.I’ve also seen this solution:
I ran into this at the last place I worked, I think the solution I came up with worked more like the latter, but I don’t have access to the exact code I used.