Desktopcanvas and picture

Hello there,

Into an old Xojo project (not used since several years) I have now some troubles with the following point.

In my project I use a “scaledpicture” object which is a picture with some useful (for my project) properties and methods… In this picture I draw lines, etc… Till here all is ok.

Now in the user interface I try to display this scaledpicture into a dekstopcanvas (which was a canvas at the beginning). Whatever I try I get an arror at compile time… DrawPicture refuse to do that.

At the time I use this instruction : Fen_graphique.Graphics.DrawPicture (Graph, 0, 0)

Fen_graphique is the desktopcanvas and Graph is the scaledpicture.

In the last Xojo version how could I get this working again ?

Thanks for help. Regards.
Philippe

Hi @Wawa_Voun , welcome to the Forum !

Which error do you get and what is the Xojo version. I suggest you tale a screen shot of the IDE showing the line of code that do not compile as well as the error message.

Thanks for the reply. Xojo is Version 2022 Release 2.

You don’t have access to the canvas’s graphics in the mousedown event. You have that access in the paint event.

1 Like

I am sorry but I dont understand.

I assume you say that instead of using a drawpicture instruction everytime I need to redraw the desktopcanvas in the code I should call the refresh event ?

But into the paint event I have also an instruction “Fen_graphique.Graphics.DrawPicture (Graph, 0, 0)” which is in error when I try to run the app.

No, he says you cannot use .Graphics …

Use g.DrawPicture in the Paint Event (after checked your Picture is not Nil.

Thanks for trying to help.

I have a desktopcanvas : Fen_graphique into my main windows.
I have then a scaledpicture (which is modified picture object) : Graph. Inside Graph I do all my drawings (lines, circles etc…).
How can I display Graph into Fen_Graphique ?
Then for exemple during a zoom I want to draw a rectangle which follow the mouse. So inside the mouse move event how can I refresh the display of Graph into Fen_Graphique ?

You tell the canvas to update. These days on macOS a .refresh is good enough. Then in the paint even you do g.drawpicture…

Add a Paint Event to Fen_Graphique.
Then in Fen_Graphique.Paint, use:


If Graph <> Nil Then
g.DrawPicture Graph,0,0
End If

To Refresh, in the MouseMove Event, use:


Me.Invalidate // If you do it too many times on the whole Canvas, it will slow down; you may have to use the optional parameters

You can add stuff in the Graph Picture and continue to use .Invalidate to display the new contents.

You also may read the link below for some more tips:

DesktopCanvas.Paint Event

Well of course it is. Look at the definition of the paint event. It says “g as graphics”. So use g:

g.DrawPicture (Graph, 0, 0)

Thanks again…

With your explanations the app now compile and works !

Sometime I need what I can call a “non persistent” drawing into Fen_graphique (typically during zoom a rectangle).

Previously I do that by drawing directly to Fen_graphique and not in Graph so when a refresh occur this disappear.

In these new version of Xojo is this still possible ? How ?