Updating from .Graphics (rb2007) to .Paint

i upgraded from RB 2007 to Xojo 2014. i had a number of deprecated items and was able to fix most but i have a couple left.

in 2007 the following worked but not in 2014. this is an area of programming where i copy what works and am not sure why but it does and that’s all i need it to do.

g = main.CanvasDD(Index).Graphics

i tried main.CanvasDD(Index).Paint(g)

and i got the following message - Type “Canvas” has no member named “Paint”

what do i do?

thx

You can’t paint into the canvas from outside the Paint event any more. Put your painting code into the Paint event or a method that’s called from the Paint event and then call Refresh or Invalidate when you want the code to execute.

It is no longer proper to reference the canvas’s graphics from outside of the canvas itself. You should refactor your code to do your drawing or painting in the paint event of the canvas itself. Use the graphics object (g) passed to the paint event by the framework. Since it appears that CanvasDD is a control set, you will have an index property passed to the paint event so that you can distinguish which member of the set has fired.

[quote=160745:@Carl Mize]i upgraded from RB 2007 to Xojo 2014. i had a number of deprecated items and was able to fix most but i have a couple left.

in 2007 the following worked but not in 2014. this is an area of programming where i copy what works and am not sure why but it does and that’s all i need it to do.

g = main.CanvasDD(Index).Graphics

i tried main.CanvasDD(Index).Paint(g)

and i got the following message - Type “Canvas” has no member named “Paint”

what do i do?[/quote]

It does not work that way. You want to look at http://documentation.xojo.com/index.php/Canvas.Paint where an example shows you how to proceed.

Alternatively, you can use the backdrop property of the canvas to draw to the Graphics property of that picture.

  • Add a picture property to main ; for instance myPic
  • Make it the backdrop of CanvasDD
  • In CanvasDD Open, create the picture myPic = new Picture(CanvasDD.width, CanvasDD.Height, 32)

Afterward, you can draw to
CanvasDD.Backdrop.Graphics

That is a good workaround you can apply with a simple search and replace of CanvasDD.Graphics with CanvasDD.Backdrop.Graphics

Since you are using a control set (array in older parlance), you have to adapt that method for each member of the control set.

This workaround is a way to reuse your older code with a minimum of modifications. For all new projects, I strongly suggest you try to apply the new method in Pain.

Its never really been “proper” BUT it worked.
The drawing model for Cocoa is substantially different from Carbon & the graphics is only valid in the paint event.
If you want to draw to something outside the paint event create a picture then in the paint event just draw the picture.