Append to canvas

How do I keep drawn objects on canvas?

I’m taking serial data and plotting on a canvas. However the old g.FillOval disappears. What am I missing?

[code]Dim i as Integer
dim yValue as Integer
dim readValue as string

yValue = 50

//Back Ground

// Grid

For i = 0 to me.width Step 20

g.DrawLine(i,0,i, me.Height)



// Draw data point
g.ForeColor= rgb(255,0,0)
g.FillOval(xPos, yValue,5,5) //timer property[/code]

If you’re doing this inside a Paint event then you will be clearing the “old” data points with your fillrect every paint.

Try moving the drawing outside the paint, draw on a picture instead then use DrawPicture inside the paint to actually put the image on the canvas.

You then have the ability to add points to the picture when you want (as you get data on from serial port) and just call invalidate, refresh or refrectrect (on the portion of the image you want to update) to show the change.

Here’s a really simple example I wrote for someone a while back

you can strip out the image resizing code if you dont need it.