I’ve got a jpeg file already listed in the Contents pane of my Xojo app because I loaded it as one of the backdrops to be used in a Canvas control. However, it’s only to be displayed when the user presses the mouse button down over that Canvas control. At all other times another jpeg picture displays in that control. I’m wondering how I can load that graphic into another canvas control at runtime, when the user pushes the mouse button down? Can I access the picture in the Contents pane or must I read it in from the jpeg file?
Here’s the picture listed in the Contents pane:
Mmmm! Not sure how to insert a picture!
The code I wrote within the MouseDown event of the Canvas control was: Me.Graphics.DrawPicture(Buttton_MainMenu_Down, 0, 0)
“Buttton_MainMenu_Down” is the ID Xojo has given that picture listed in the Contents pane.
You do not/should not (and I thought could not) access the graphics property of a canvas control directly…
Everything should happen during the PAINT event of the canvas…
So in the PAINT event you probably want “g.drawpicture button_menu_down,0,0”
assuming button_menu_down is a picture
but there is no need for a mouse click… it will just draw it… so it is kind of hard to tell exactly what it is you are wanting to do.
Jeff, I’ve had a look at that example. That’s very helpful thanks.
I think I’m nearly there. But I need to load a picture that is already listed in the Contents pane, called “Buttton_MainMenu_Down”, into a Picture control. Is there a way to do that?
If the image is in the contents, then you just call it by name. Any resource you drag into the project becomes a property of the same name (without the file extension).
So if I want to load that picture into a canvas control, Introduction to Programming with Xojo says to do this call:
Canvas1.Graphics.DrawPicture(myPic,x,y)
myPic is a picture that has already been loaded into a Picture control.
If I’m wanting to load my picture that’s in the contents pane - Buttton_MainMenu_Down - into the Canvas control how would i do that please?
Replace “MyPic” with “Button_MainMenu_Down”. However, that code is out of date and should no longer work. Try replacing the backdrop instead, in the MouseDown of your canvas: