day0ops
day0ops

Reputation: 7482

Flickering on winform UI

I've implemented a winform UI for Microsoft Robotics Studio to display some sensor data. Currently it draws on a panel every 100 milliseconds using the function below. The issue is I'm seeing flickering on the panel I'm drawing and when dragging the window it feels very sluggish. Based what other people have encountered on this forum I used DoubleBuffered = true when creating the form to no avail. Any tips on how I can improve this ? Thanks in advance.

This function draws lines on the panel representing a radar,

    private void DrawRadarLines()
    {
        myPen = new Pen(Color.Red, 2);
        formGraphics = radarMap.CreateGraphics();

        for (int i = 0; i < sensorNetworkNum * 5; i++)
        {
            formGraphics.DrawLine(myPen, 
                (float)(195 - radarMapLines[i, 0] * scalingFactor), 
                (float)(195 - radarMapLines[i, 1] * scalingFactor), 
                (float)(195 - radarMapLines[i, 2] * scalingFactor), 
                (float)(195 - radarMapLines[i, 3] * scalingFactor));
        }

        myPen.Dispose();
        formGraphics.Dispose();
    }

Upvotes: 1

Views: 898

Answers (1)

Hans Passant
Hans Passant

Reputation: 941218

That's pretty inevitable when you use CreateGraphics(), you are drawing straight to the screen. Just don't, call radarMap.Invalidate() instead and move the code to a Paint event handler for radarMap. Now double-buffering the control will work.

Upvotes: 2

Related Questions