在聚焦窗体上单击丢失 [英] Click lost on focusing form

查看:110
本文介绍了在聚焦窗体上单击丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
有没有办法总是让一个点击,通过对表单有影响,使表单聚焦?

Question: Is there a way to always let a click, that brings a form in to focus, through an have effect on the form?

背景:
在我的(C#win form)应用程序失焦的情况下,我可以将鼠标悬停在窗体上,并获得表示鼠标位置的阴影和边框。

Background: With my (C# win form) application out of focus I can hover the form and get shades and borders indicating where my mouse is.

示例菜单条目(文件)表单获得焦点,但文件菜单没有获得点击。这需要额外点击。

Clicking for example a menu entry (File) the form gets focus but the file menu does not get click. This takes an additional click.

对于表单上的普通按钮只需一次点击。

For an ordinary button on the form only one click is required.

推荐答案

这可以通过在点击发生之前设置焦点来修复。 Se代码:

This can be fixed by setting focus before the click occurs. Se code:

class ToolStripEx : System.Windows.Forms.ToolStrip
{
    protected override void WndProc(ref Message m)
    {
        // WM_MOUSEACTIVATE = 0x21
        if (m.Msg == 0x21 && this.CanFocus && !this.Focused)
        {
            this.Focus();
        }
        base.WndProc(ref m);
    }
}

此方法也适用于MenuStrip

This approach also works on MenuStrip

这篇关于在聚焦窗体上单击丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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