Canvas Variations

I am attempting to create a canvas that will change what picture is displayed depending on a global variable, of which is decided earlier. I have it set up so that the the number selected for the variable (integer) is the name of an image. However, I cannot figure out how to make the canvas display the image, as it comes up with this error:

Parameter “image” expects class Picture, but this is class Canvas.
g.DrawPicture(pcard, 0, 0, 50, 66, 0, 0, 632, 761)

pcard is the global variable

Any assistance would be appreciated, or an alternative way to accomplish the same result would also help as I am new to Xojo.
Thanks!

dim pic as Picture
you need select case integer value
pic = picturename in your project

g.DrawPicture(pic , 0, 0, g.width, g.height, 0, 0, pic.width, pic.height)

you can trigger the repaint if you call the .invalidate method of this canvas

if you subclass your canvas it will be more handier and you could add a property at your custom control.

[quote=489766:@Markus Rauch]dim pic as Picture
you need select case integer value
pic = picturename in your project

g.DrawPicture(pic , 0, 0, g.width, g.height, 0, 0, pic.width, pic.height)

[/quote]

When I attempt to do this I receive a type mismatch error (expected class picture but got class canvas), what can I do to prevent this? Thanks

i think your property is type canvas but you use it as picture?
check if your propertys have correct type.

Look in the examples, there is graphics etc you’ll see how it works

Pic is a canvas
drawpicture expects to be given a picture.

We can see no sign of this here

You have a variable - lets call that picnumber
When the variable is changed, call you canvas’ invalidate event
That will make it paint

In the Paint event, instead of

g.DrawPicture(pcard, 0, 0, 50, 66, 0, 0, 632, 761)

do this

select picnumber
case 1
g.DrawPicture(picture1, 0, 0, 50, 66, 0, 0, 632, 761)
case 2
g.DrawPicture(picture2, 0, 0, 50, 66, 0, 0, 632, 761)
case 3
g.DrawPicture(picture3, 0, 0, 50, 66, 0, 0, 632, 761)
end select

Although you SAY [quote]number selected . . . is the name of an image[/quote]
Im pretty sure you cannot have an image in the app whose name is just a number.
What is it really called?