Tool Strip Container Tools Strip Lost Focus and Double Click

こ雲淡風輕ζ 提交于 2020-01-16 19:40:54

问题


VB.Net 2008 Express Edition

"Form1" has a ToolStripContainer1.TopToolStripPanel which contains a ToolStrip with buttons. The buttons work on ONE click when "Form1" is active. If I click on another window and then return to "Form1" the ToolStrip buttons take TWO clicks to activate. The first click returns focus to "Form1" and the subsequent click fires the button event. I want the buttons to work on the first click and not require two clicks.

Note that ordinary buttons on "Form1" that are not part of the ToolStrip work on the first click when returning from another window/form!!!!????


回答1:


That's standard behavior. You can see Microsoft Outlook does the same thing if it doesn't have focus and you click on a tool button that is visible on the screen.

But you can override that behavior with your own version:

Public Class ToolStripEx
  Inherits ToolStrip

  Private Const WM_MOUSEACTIVE As Int32 = &H21

  Public Sub New()
    MyBase.New()
  End Sub

  Protected Overrides Sub WndProc(ByRef m As Message)
    If m.Msg = WM_MOUSEACTIVE AndAlso Me.CanFocus AndAlso Not Me.Focused Then
      Me.Focus()
    End If
    MyBase.WndProc(m)
  End Sub

End Class


来源:https://stackoverflow.com/questions/7121624/tool-strip-container-tools-strip-lost-focus-and-double-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!