(I'm sorry for my poor English.)
My work is - drawing lines in Panel.
For this, I overrided the OnRender method of Panel, and put a below code.
/// <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开发者_如何学Go < 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));
}
Now, you know what is the my job.
Upper code gives me correct operation, except low performance.
It is really slow....
What is wrong? How can I make it more faster?
Do you try the method of "OffSrceen" or "DoubleBuffer" for your onrender in panel, and when you update the panel ,only update the changed parts!
Interesting, I found -- an elements with OnRender can be slower than many FrameworkElements has visual.
Therefore, putting many Line controls to Panel can be solution.
精彩评论