C#Invalidate不调用paint方法

l46*_*kok 6 .net c# paint invalidation winforms

我用OnPaint方法覆盖了在屏幕上绘制椭圆.

    protected override void OnPaint(PaintEventArgs e)
    {
        MessageBox.Show("Paint");
        if (debugStarted)
        {
            int y = rtbLogicCode.PlaceToPoint(new Place(0, debugLine)).Y;
            if (rtbLogicCode.GetVisibleState(debugLine).ToString() == "Visible")
            {
                e.Graphics.FillEllipse(new LinearGradientBrush(new Rectangle(0, y, 15, 15), Color.LightPink, Color.Red, 45), 0, y, 15, 15);
            }
            base.OnPaint(e);
        }
    }

    private void rtbLogicCode_Scroll(object sender, ScrollEventArgs e)
    {
        this.Invalidate();
    }
Run Code Online (Sandbox Code Playgroud)

滚动事件(在Richtextbox上)被正确处理,但即使我使表单无效,它也没有调用OnPaint函数(消息框未显示).

可能的原因是什么?

编辑:我忘了提到我的子窗体的初始化函数(使用MDI属性添加为主窗体的控件),我设置以下样式:

 private void LogicCodeInit()
    {


            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);


    }
Run Code Online (Sandbox Code Playgroud)

Edit2:我也忘了提到子窗体是作为TabControl的控件添加的.然后将TabControl添加为主窗体的控件.

Jcl*_*Jcl 11

通话UpdateInvalidate.Invalidate只有在有焦点的情况下重新绘制表格,它可能没有得到重点,因为它是作为一个TabControl孩子添加的.

MSDN文档:

调用Invalidate方法不会强制执行同步绘制; 要强制执行同步绘制,请在调用Invalidate方法后调用Update方法.如果在没有参数的情况下调用此方法,则会将整个客户端区域添加到更新区域.