工具条容器工具条失去焦点并双击 [英] Tool Strip Container Tools Strip Lost Focus and Double Click

查看:165
本文介绍了工具条容器工具条失去焦点并双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB.Net 2008 Express Edition

VB.Net 2008 Express Edition

"Form1"具有一个ToolStripContainer1.TopToolStripPanel,其中包含带有按钮的ToolStrip.当"Form1"处于活动状态时,这些按钮仅需单击一下即可使用.如果我单击另一个窗口,然后返回到"Form1",则ToolStrip按钮需要两次单击才能激活.第一次单击将焦点返回到"Form1",随后的单击将触发按钮事件.我希望按钮在第一次单击时起作用,而无需单击两次.

"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.

请注意,从另一个窗口/窗体返回时,第一次单击时,"Form1"上不属于ToolStrip的普通按钮就起作用!!!

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

推荐答案

这是标准行为.您可以看到Microsoft Outlook在没有焦点的情况下执行相同的操作,然后单击屏幕上可见的工具按钮.

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

这篇关于工具条容器工具条失去焦点并双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆