Using a string name to assign window backdrop

Ok I am not finding a solution to this. I am attempting to create a template system for my app. I do not see a way to assign the backdrop of a windows via a string name that matches a loaded image name

for example

Dim mypic as string
mypic = "someimage"  // some image is an image that is loaded in and works when manually assigned via drop down


windowname.backdrop = mypic   

I know its not that simple but need to know how I could use the string that has an exact match name as an image I want to use

Use the name directly rather than as a quoted string:

windowname.backdrop = someimage // no quotes

Thanks, but I am pulling it from a storage preference setting upon application load and hoping I can convert the string to something that can be used as the backdrop image name

Your image must be somewhere. I would save the name of the file to the preferences and then load the image with this name from the harddisk to draw it in the paint event.

I get I may not be explaining what I am attempting to do properly and I apologize and thank you all for your help.

The image is already in the project, I have a few of them that I have dragged in to the project and their names begin with tmK_

ie tmk_blue, tmk_ red

The user selected for instance the image red with the name in Xojo as tmk_red so I have this name as a stored the the prefs file.

When the user loads the app the next time the application retrieves what image the user wants as the background. In this case it would be tmk_red the exact same name that xojo references it as when I manually select it from the windows dropdown for backdrop.

Since there will be a few images to select from I needed a way to reference them from a string name from the prefs file. The image again is stored with int project and not loaded externally

You have 2 possibilities:

  • If prefvalue = “image1” then
    me.backdrop = image1
    elseif
    and so on

  • or the one I mentioned before. The path reference can be one to the own app.

[quote=330572:@Beatrix Willius]You have 2 possibilities:

  • If prefvalue = “image1” then
    me.backdrop = image1
    elseif
    and so on

  • or the one I mentioned before. The path reference can be one to the own app.[/quote]
    Thanks I was afraid it would have to be done this way, was hoping for a “shortcut” using the string name for the image due to how many places I will be calling it. Thanks again

Make a method SetBackgroundImage

In there have the code to set the background

Call the method where you need to.

Rule #1: don’t write the same code multiple times

Btw there is a better way. I’ll write it up later when I have time.

Awesome looking forward to it

I routinely use a dictionary for such a thing.

self.backdrop = dico.value("mypic")

[quote=330582:@Michel Bujardet]I routinely use a dictionary for such a thing.

self.backdrop = dico.value("mypic")

Thanks Michel, I’ll test that out!

Check out http://developer.xojo.com/xojo-io-specialfolder$GetResource. On Windows images included in the project exist there (and I would imagine for other targets) so loading the image from a folder item should remove the requirement to use Select Case or Nested If Then statements.

Lots of good suggestions in this thread, thank you all