I have a .NET 2.0 WinForms application with a ToolStrip on my main form. Sometimes, the ToolStrip icons don't resppond to the first mouse click, so I have to click the icon twice. It's just a standard ToolStrip with several icons and tooltip texts, I don't do anything special. Is this common?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
I had the same problem some times ago, and I found a solution in Rick Brewster's blog. The idea is to overwrite 'WndProc' in a derived class ToolStripEx. The core of that solution looks like this:
I've had that in other dev environments (VB6), and it turned out to be because the first click was being absorbed by the toolbar to acquire the focus. Or, to put it another way, the toolbar wouldn't respond to a click until it had the focus. To test this, try clicking on an empty part of the toolbar before you click on the button. If you never have to click twice on the button after you've clicked on the toolbar then that might be the problem. I think they I got around it (and this was years ago, so please excuse the hack) was to programatically give the focus to the toolbar in the MouseOver event.
You can create your own class that inherits from the ToolStrip and use a custom property
ClickThrough
to switch the behaviour on or off:If the application window hasn’t got the focus, you have to click the ToolStrip button twice. The first click sets the focus to the window, the second raises the click event. This is (unfortunately) the default behaviour and it’s by design. Microsoft Word shows the same behaviour (even though the .NET ToolStrip is not the same control).