views:

29

answers:

2

(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 < 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?

A: 

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!

Smart_Joe
Hmm.. your answer cannot be solution. It correctly works in WinForm Framework, but not in WPF. WPF uses different graphic-layout system.
illef
Oh,I am sorry!The above-mentioned offer some ideas for your performance drawing!
Smart_Joe
A: 

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.

illef