(我为我糟糕的英语感到抱歉。)
我的工作是-在面板中绘制线条。
为此,我重写了面板的OnRender方法,并放入了下面的代码。
/// <summary>
/// 라인의 두께
/// </summary>
private const double LINE_THICKNESS = 0.5d;
/// <summary>
/// 가로줄의 간격
/// </summary>
private const double GAP_PER_WIDTHLINE = 30d;
/// <summary>
/// 세로줄의 간격
/// </summary>
private const double GAP_PER_HEIGHTLINE = 12d;
int lineCount = 0;
for (double x = GAP_PER_WIDTHLINE; x < this.ActualHeight; x += GAP_PER_WIDTHLINE)
{
lineCount++;
if (lineCount % 5 == 0)
{
dc.DrawLine(solidPen, new Point(0, x), new Point(this.ActualWidth, x));
lineCount = 0;
}
else
dc.DrawLine(dotPen, new Point(0, x), new Point(this.ActualWidth, x));
}
//# 세로줄
lineCount = 0;
for (double y = GAP_PER_HEIGHTLINE; y < this.ActualWidth; y += GAP_PER_HEIGHTLINE)
{
lineCount++;
if (lineCount % 5 == 0)
{
dc.DrawLine(solidPen, new Point(y, 0), new Point(y, this.ActualHeight));
lineCount = 0;
}
else
dc.DrawLine(dotPen, new Point(y, 0), new Point(y, this.ActualHeight));
}现在你知道我的工作是什么了。
上面的代码给了我正确的操作,除了低性能。
它真的很慢...
怎么啦?我怎样才能让它更快?
发布于 2010-09-17 17:29:24
你是否尝试过在面板中使用"OffSrceen“或"DoubleBuffer”的方法,当你更新面板时,只更新更改过的部分!
发布于 2010-09-20 09:02:41
有趣的是,我发现带有OnRender的元素可能比许多FrameworkElements具有的视觉效果要慢。
因此,将多个Line控件放到Panel中是一种解决方案。
https://stackoverflow.com/questions/3734065
复制相似问题