开发者

Cancel textbox from sending MouseLeave Messages

开发者 https://www.devze.com 2023-03-26 19:23 出处:网络
Is there a way I can cancel the WM_MOUSELEAVE message from a text box? I ha开发者_运维百科ve another control directly on top of it (I\'m trying to get the Windows-drawn border). I\'m manually invoki

Is there a way I can cancel the WM_MOUSELEAVE message from a text box?

I ha开发者_运维百科ve another control directly on top of it (I'm trying to get the Windows-drawn border). I'm manually invoking WM_MOUSEMOVE in the MouseMove event of that control to get the Aero blue border around the textbox to light up. Using Spy++, I see its firing WM_MOUSELEAVE even though I'm still in its bounds. That causes the blue border to disappear/reappear in a flicker.

edit I tried @Jeroen's answer and it reduces the flicker, but I still can't keep the glow on or it sticks too long.

        if (m.Msg == (int)Win32Api.WindowsMessages.MouseLeave)
        {
            var mousePosition = PointToClient(MousePosition);
            if (mousePosition.X < 0 || mousePosition.X > Width ||
                mousePosition.Y < 0 || mousePosition.Y > Height)
                base.WndProc(ref m);
            return;
        }

        base.WndProc(ref m);


Maybe this is what you're looking for. It would require you to replace the TextBox definition with tb but maybe there's a more elegant way.

    public class tb : TextBox
            {

                private const int  WM_MOUSELEAVE = 0x02A3;

                protected override void WndProc(ref Message m)
                {
                    if (m.Msg == WM_MOUSELEAVE)
                    {
                        // not passing the message on, so does nothing.
                        // handle it yourself here or leave empty.
                    }
                    else
                    {
                        // otherwise let windows handle the message
                        base.WndProc(ref m);
                    }
                }
            }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号