Canvas error help.

Im getting errors when trying to run my project. The last time I opened this particular project was in a previous version of XOJO and it ran just fine. Now I tried to run the project and there are all kinds of errors that look something like this: UserSetupWindow.DisplayUserPhoto, line 54 Type "Int32" has no member named "DrawPicture" UserPhotoCanvas.Graphics.DrawPicture (pp, 0+iXOffset, 0+iYOffset, UserPhotoCanvas.Graphics.Width, UserPhotoCanvas.Graphics.Height, 0, 0, iScaledWidth, iScaledHeight)

Im not sure what changed but I can’t seem to figure out how to solve it. Can anyone help?

canvas.graphics is deprecated since a long time, and has been removed from the last xojo 2018r3
you must get the graphics from the paint event parameter g instead.
and sometimes re-code a lot of things…

You need to do your drawing in the Canvas.Paint event handler and not using the Canvas.Graphics property as it was removed in 2018r3.

So in its simplest form you might be able to do this in UserPhotoCanvas.Paint:

g.DrawPicture(pp, 0 + iXOffset, 0 + iYOffset, g.Width, g.Height, 0, 0, iScaledWidth, iScaledHeight)

And in UserSetupWindow.DisplayUserPhoto, remove the code that attempts to draw a picture to UserPhotoCanvas.Graphics and instead have it tell the Canvas to draw:

UserPhotoCanvas.Invalidate(False)

Edit: Fixed up the Paint event code sample a bit.

Thank you for the help.

I have this question too. I have a lot of complicated graphics with various subroutines. I have made dedicated modules to figure out the graphics for each canvas (about a dozen on various tabs). When I go to compile I get 183 errors of what used to work. Is there no way to off load the graphics processing into subroutine methods rather than cramming it all into a single paint event?

Sure. You can call any of those methods from the paint event, but instead of writing directly to the canvas.Graphics object, you’ll need to pass the Paint event’s g parameter (g as Grsphics) to those methods and draw to that instead.

NOW:

Canvas1.graphics.<be blue> Canvas1.graphics.<draw a circle> Canvas1.graphics.<draw some words>

All of those things vanish from screen when the control is invalid such as when it has been covered by another window

Change to the Canvas1.paint event, which has a g parameter:

DrawStuffOnMe (g)

DrawStuffOnMe would contain

g..<be blue> g.<draw a circle> g.<draw some words>

So most of the work is replacing Canvas1.graphics to be g

I have some code that forces a canvas to redraw in response to some changes in the data. So I have calls like this

draw_MyCanvas( winMain.MyCan.Graphics )

I guess these rattled the cage of the canvas and caused the paint event to fire. Can you tell me how do I change these?

When you need the canvas to repaint, use MyCan.invalidate

In the MyCan.Paint() event, put

draw_MyCanvas( g )

These pages might also be helpful for you:

Essentially you want to do as Jeff and others suggest. Pass the g parameter to your own methods and when other methods need to redraw, call Invalidate on the Canvas.

With 184 compile errors from this alone its a headache.

When some underlying data changes, I used to wake up the canvas to refresh it like this
draw_cl2( winMain.canCl2.Graphics )

I tried calling this (from outside) and get an error.
winMain.canCl2.Graphics.invalidate

Try

winMain.canCl2.invalidate

It’s the canvas you want to invalidate.

[quote]Greg O’Lone
Try

winMain.canCl2.invalidate
It’s the canvas you want to invalidate.[/quote]

…and then the canvas’ Paint event will contain

draw_cl2( g )

Actually I got it to work now. Thanks everyone. Its simply a matter to invalidate the canvas, and that apparently creates a new instance and fires the paint event. Thanks again!