Updating Code That Used the Graphics Property
From Xojo Documentation
Prior to 2018r3 Window and Canvas both had a Graphics property that you could access and draw to. This was deprecated in 2011 because it had significant performance issues on all platforms. The preferred way to draw your graphics since 2011 has been to use the Window.Paint or Canvas.Paint event handlers and the supplied parameter g As Graphics.
Starting with 2018r3, this Graphics property was removed from Window and Canvas so if you had code that was still relying on it, that code will no longer compile. Here are some tips on how you can migrate your code to use the Paint event handlers and tell the Canvas to update with a call to Invalidate.
If your code was simple and just drawing a Picture to the Graphics property, then you would just move the code to the Paint event handler. For example, this code is drawing a picture:
Where that code existed, you would tell it to redraw Canvas1:
And then in the Canvas.Paint event handler you would draw the picture:
More Advanced Drawing
If your code was doing more advanced drawing to the Graphics property then you will need to do more substantial changes to your code. Since you ideally want to do all the drawing in the Paint event handler you may need to use a separate means to store what was being updated (such a properties or a class) and then in the Paint event handler use these values to do the drawing.
So say you had code in a MouseDown event that was drawing a point on the Canvas when the mouse was clicked like this:
You would now create properties to store the X and Y values from the MouseDown event:
In MouseDown you would now save the values to the properties and tell the Canvas to update when the mouse was clicked:
LastClickY = Y
Lastly you would put code in Canvas.Paint to draw the point:
Although the above is recommended, you may find that making all the changes needed is more than you want to change. Another technique you can use is to do the drawing in an offscreen picture and then draw the picture in the Canvas. With this technique you create a Picture property for your drawing:
You then initialize it to the size you want using the Window.BitmapForCaching method (so that it is HiDPI compatible):
And then everywhere where you were drawing directly to Graphics you now draw to your Picture property and tell the Canvas to update. So instead of:
Canvas1.Graphics.DrawLine(0, 0, 100, 100)
your code would look like this:
MyDrawing.Graphics.DrawLine(0, 0, 100, 100)
And in the Paint event for Canvas1: