P
Philipp
Hi folks!
The ToolStrip implementation in .NET follows the behavior in the Office
(2003) implementation, where buttons are hovered even if the form is
not focused, but users have to click twice before the event gets fired
(once for focus and once for the button click). This behavior is very
annoying and leaves me wondering why nobody at MS had a serious thought
about that before. Obviously they have fixed it in Office 2007: buttons
aren't hovered if the window has no focus. I prefer to handle the click
anyway, so here's a quite simple workaround:
Public Class ToolStripEx
Inherits System.Windows.Forms.ToolStrip
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal ParamArray items() As
System.Windows.Forms.ToolStripItem)
MyBase.New(items)
End Sub
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
'WM_MOUSEACTIVATE = 0x21
If m.Msg = &H21 AndAlso Me.CanFocus AndAlso Not Me.Focused Then
Me.Focus()
MyBase.WndProc(m)
End Sub
End Class
The class is named ToolStripEx for simplicity and should appear in the
toolbox after compilation. A search & replace would do the work for
changing the declaration of existing ToolStrips throughout your
project.
Same resolution applies to MenuStrips.
The example should be easy to translate to any other language. At least
I hope so
Best Regards
Philipp Fabrizio
The ToolStrip implementation in .NET follows the behavior in the Office
(2003) implementation, where buttons are hovered even if the form is
not focused, but users have to click twice before the event gets fired
(once for focus and once for the button click). This behavior is very
annoying and leaves me wondering why nobody at MS had a serious thought
about that before. Obviously they have fixed it in Office 2007: buttons
aren't hovered if the window has no focus. I prefer to handle the click
anyway, so here's a quite simple workaround:
Public Class ToolStripEx
Inherits System.Windows.Forms.ToolStrip
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal ParamArray items() As
System.Windows.Forms.ToolStripItem)
MyBase.New(items)
End Sub
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
'WM_MOUSEACTIVATE = 0x21
If m.Msg = &H21 AndAlso Me.CanFocus AndAlso Not Me.Focused Then
Me.Focus()
MyBase.WndProc(m)
End Sub
End Class
The class is named ToolStripEx for simplicity and should appear in the
toolbox after compilation. A search & replace would do the work for
changing the declaration of existing ToolStrips throughout your
project.
Same resolution applies to MenuStrips.
The example should be easy to translate to any other language. At least
I hope so
Best Regards
Philipp Fabrizio