Activate a form and process button click at the same time?

给你一囗甜甜゛ 提交于 2019-12-03 14:00:36
dwidel

What you need to do is create a class that inherits ToolStrip and handles the WndProc. This is one way to do it. There are others.

private class MyToolStrip : ToolStrip
{
    private const uint WM_LBUTTONDOWN = 0x201;
    private const uint WM_LBUTTONUP   = 0x202;

    private static bool down = false;

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_LBUTTONUP && !down)
        {
            m.Msg = (int)WM_LBUTTONDOWN;
            base.WndProc(ref m);
            m.Msg = (int)WM_LBUTTONUP;
        }

        if (m.Msg == WM_LBUTTONDOWN) down = true;
        if (m.Msg == WM_LBUTTONUP)   down = false;
        base.WndProc(ref m);
    }
}

I've also seen this solution:

protected override void WndProc(ref Message m)
{
    // WM_MOUSEACTIVATE = 0x21
    if (m.Msg == WM_MOUSEACTIVATE && this.CanFocus && !this.Focused)
        this.Focus();
    base.WndProc(ref m);
}

I ran into this at the last place I worked, I think the solution I came up with worked more like the latter, but I don't have access to the exact code I used.

if u have Form without borders, so this logic was working for you built in :)

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