开发者

Really strange ToolStripButton event problem

I am making a CustomControl based on a ToolStripButton control, I am trying to know when the mouse is Hover the button to draw it differently. Here is a quick view of my code :

    private bool m_IsHover = false;        

    ...

    protected override void OnMouseEnter(EventArgs e)
    {
        m_IsHover = true;
        Debug.WriteLine("Mouse IN");
        base.OnMouseEnter(e);
    }

    protected override void OnMouseLeave(EventArgs e)
    {
        m_IsHover = false;
        Debug.WriteLine("Mouse OUT");
        base.OnMouseLeave(e);
    }

    ...

    protected override void OnPaint(PaintEventArgs e)
    {
        // Define rectangle used to draw
        Rectangle borderRec = new Rectangle(0, 0, this.Width - 1, this.Height - 1);

        if (m_IsHover)
        {
            // Draw border
            e.Graphics.DrawRectangle(m_BorderPen, borderRec);

            ...
        }
        else
        {
            // Default draw
            base.OnPaint(e);
        }
    }

M开发者_运维知识库y problem is that I clearly see in the debug panel that Mouse IN and Mouse OUT are right, so variable should be correctly set, but in the OnPaint event, I never enter in the m_IsHover conditionnal ...

I really don't understand what the problem is, it seem so easy ...


The ToolStripItem.Select() method runs on MouseEnter. Call this.Invalidate() to force a repaint.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜