【发布时间】:2010-12-17 00:48:24
【问题描述】:
我有一个非常大的 C# .net 2.0 winforms 应用程序,它有一些绘图问题。
当进入不同的表单时,您可以看到控件被绘制,甚至表单的标题栏被调整大小然后消失。
所有其他表单继承自的基本表单在其构造函数中具有以下代码。包括将 DoubleBuffering 设置为 true。
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.UpdateStyles();
表单也有一个背景渐变,但删除它对速度没有影响。
所有控件和表单都继承自基本版本。
我可以添加或检查什么来帮助提高绘图速度?
OnPaint 中的代码
if (this.b_UseBackgroundGradient)
{
Graphics graphics = e.Graphics;
Rectangle backgroundRectangle = this.ClientRectangle;
this.SuspendLayout();
if (backgroundRectangle.Width != 0 && backgroundRectangle.Height != 0)
{
using (Brush backgroundBrush = new LinearGradientBrush(backgroundRectangle, base.BackColor, this.BackGradiantColour, LinearGradientMode.ForwardDiagonal))
{
graphics.FillRectangle(backgroundBrush, backgroundRectangle);
}
}
this.ResumeLayout();
}
else
{
base.OnPaint(e);
}
【问题讨论】:
-
你在 OnPaint 方法内部做些什么吗?
-
在此更改后尝试在远程桌面上使用该表单。
标签: c# winforms drawing performance