Hello all,

I am making a dynamic graph which is shown on the "form" everytime when I receive some character from serial port.

To do this. I create graph layout by overriding OnPaint method:

Code:
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics gPlot = e.Graphics;
            DrawAxis(gPlot, coordinates..);
            gPlot.Dispose();
        }

//On receiving character, call updateGraph method

        private void UpdateGraph(int aData)
        {
            PointF currentPoint = TranslateValueToPixel(aData); //I receive pixel point to be drawn 
            Graphics aGPlot = this.CreateGraphics();
            aGPlot.DrawLine(Pens.Green, lastPoint, currentPoint);
            lastPoint = currentPoint;
            aGPlot.Dispose();  //have tried without disposing too
        }
My problem is that it works well if the form is on the screen (in scope) but if it becomes out of scope, the graph refreshes itself, which means all the points that I have drawn on the graph are lost (although graph itself that was created with OnPaint() remains) and it starts drawing of new aData. The problem is clear and I understand it too but is there any solution to it?

Regards,
Ricky