Hi Guys,

I am having a little challenge drawing and rendering persistent graphics.

I am attempting to plot an XY graph using dynamic data where I receive a time value (X) and an increment value (Y)
I have created a picturebox object to plot the values to and programmatically define my centreline zero
I then take the incoming time event in seconds and the incoming incremental value which can range from -6 through to 6 inclusively.
Then I add that value to the incremental total and if that value is positive, I plot a Blue vertical line from the zero point to the value on the Y axis, where the X axis is automatically incremented by one (time in seconds) and if it is a negative value then I plot it in Red with a descending line from the zero point.

The above is both a description of what I am trying to do with the incoming data.

Where I am having difficulty is drawing the graphics in a persistent manner so that as the data arrives, the previous plot is not erased by the new incoming plot.

If I simulate the information and draw it all in one routine, then I get a nice graphic but when I attempt to plot it as the data arrives, I either get a single line that plots each time or I get nothing (most frustrating)

Here is my simulated data code which should plot some simulated red and blue solid arcs. (not actual arcs as the data is in column form)

I initially tried plotting direct to the form which worked if I did it all in one go, but of course I couldn't add any new data as calling the routine refreshed the form and I lost the previous plots.

Then I created a picturebox object and defined a rectangle area, I also defined a bufferedgraphicscontext object so that I could draw the column to the object and then render the object to the rectangle on the picturebox so that I could cumulatively add columns to the buffered object and then render the object, thus preventing the loss of previous plots as the whole plot graph would be rendered each time. This is where I am at and other than getting the render to flash on and instantly disappear, I have been unable to figure out how to keep the rendered image persistent.

I am hoping that you might be able to point out where I am going wrong?

Code:
Public Class Form1
    Public MyImage As New BufferedGraphicsContext
    Public rectangle = New Rectangle(x:=0, y:=0, width:=755, height:=201)
    Public MyWorm As System.Drawing.BufferedGraphics
    Public pen1 As Pen = New Pen(Color.White, 2)
    Public pen2 As Pen = New Pen(Color.DarkRed, 1)
    Public pen3 As Pen = New Pen(Color.Navy, 1)
    Dim x As Integer
    Private Sub Form_Load(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
        Me.Width = 820
        Me.Height = 253
        Me.BackColor = Color.DarkSlateGray
        DoubleBuffered = True
        MyWorm = MyImage.Allocate(PictureBox1.CreateGraphics, rectangle)
        With MyWorm.Graphics
            .CompositingMode = Drawing2D.CompositingMode.SourceOver
            .CompositingQuality = Drawing2D.CompositingQuality.AssumeLinear
            .SmoothingMode = Drawing2D.SmoothingMode.HighQuality
            .InterpolationMode = CType(Drawing2D.QualityMode.High, Drawing2D.InterpolationMode)
            .PixelOffsetMode = Drawing2D.PixelOffsetMode.None
        End With
        PlotWorm(Nothing, Nothing)
    End Sub
    Public Sub PlotWorm(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
        Do While x < 121
            For y = 0 To 60 Step 6
                x += 1
                MyWorm.Graphics.DrawLine(pen3, 34 + x, 106 - y, 34 + x, 2 + y)
                MyWorm.Render()
            Next y
            For y = 60 To 0 Step -6
                x += 1
                MyWorm.Graphics.DrawLine(pen3, 34 + x, 106 - y, 34 + x, 2 + y)
                MyWorm.Render()
            Next y
        Loop
        Do While x < 241
            For y = 0 To -60 Step -5
                x += 1
                MyWorm.Graphics.DrawLine(pen2, 42 + x, 108 - y, 42 + x, 2 + y)
                MyWorm.Render()
            Next y
            For y = -60 To 0 Step 5
                x += 1
                MyWorm.Graphics.DrawLine(pen2, 42 + x, 108 - y, 42 + x, 2 + y)
                MyWorm.Render()
            Next y
        Loop
        Do While x < 361
            For y = 0 To 60 Step 4
                x += 1
                MyWorm.Graphics.DrawLine(pen3, 54 + x, 106 - y, 54 + x, 2 + y)
                MyWorm.Render()
            Next y
            For y = 60 To 0 Step -4
                x += 1
                MyWorm.Graphics.DrawLine(pen3, 54 + x, 106 - y, 54 + x, 2 + y)
                MyWorm.Render()
            Next y
        Loop
        Do While x < 481
            For y = 0 To -60 Step -3
                x += 1
                MyWorm.Graphics.DrawLine(pen2, 66 + x, 108 - y, 66 + x, 2 + y)
                MyWorm.Render()
            Next y
            For y = -60 To 0 Step 3
                x += 1
                MyWorm.Graphics.DrawLine(pen2, 66 + x, 108 - y, 66 + x, 2 + y)
                MyWorm.Render()
            Next y
        Loop
    End Sub

End Class
I am looking forward to your advice and guidance.

Regards,
Antony