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添加为主窗体的控件.
| 归档时间: |
|
| 查看次数: |
15243 次 |
| 最近记录: |