我已经重写了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();
}
滚动事件(在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);
}
编辑2:我还忘记提到子表单被添加为TabControl的一个控件。然后TabControl作为主界面的一个控件被添加。
this.Invalidate()
吗?如果通过调整窗口大小来强制重绘,会发生什么? - sloth