Scrolling graphics on canvas

I’ve read a lot of old posts about scrolling canvases, read the documentation but still having difficulties. Here’s the scenario:

I am directly drawing a complicated graphic image to a canvas, not a picture. Here’s the simple code which is in the Paint event of the canvas:

[code]g.ScaleX = PS.ScaleX
g.ScaleY = PS.ScaleY


The scaling is so I can zoom in on the drawing. The PS.PrintPuzzle is the whole complicated drawing set of methods. It works fine except when I try adding this to the Paint event:

Me.Scroll (-scroll2, -scroll1)

I get the drawing followed by the scrolling and a general mess. Do I have to use DrawPicture to get this to work?

You could pass scroll amounts to your printpuzzle method and just add that to every x and y coordinate.

Or in a more simple way use a clip

PS.PrintPuzzle(g.clip(-scrollX, -scrollY, neededHeight, neededWidth))

In this way your draw is with the original coordinates

In any case (and Greg’s suggestion is right) you should try to avoid drawing commands that you know will happen out of the used graphic area.

Thanks for the replies. (I forgot I had posted the question. Busy weekend.)

I’ll try Antonio’s idea first. I had done, in a previous rendition, a lot of x,y adjusting and it seemed to clunk up the code. But it may be what I need to do.