Set the source of an image (picture object) on a custom dialog - Forum

Forum Navigation
You need to log in to create posts and topics.

Set the source of an image (picture object) on a custom dialog

Hi,
I want to show an image from a web url on a custom dialog. So I have a custom dialog with a picture object without the source property set, to be set before opening the dialog.
From a button I set the source property and open the dialog but the image is not loaded.
e.g. (Image2 is on custom dialog)
setvar [imgUrl] "https://upload.wikimedia.org/wikipedia/commons/b/b0/European_grey_wolf_in_Prague_zoo_2.jpg"
SetObjectAttribute "Image2" "src" "[imgUrl]"
OpenDialog "dlgImg"

Why isn't the image loading? Maybe the image on the dialog is created at runtime and therefore you can't set the property of an object that doesn't yet exist?

If as an alternative to the picture object I use a container with this html set for example. (container is on custom dialog)
<img id="Image3" src="[imgUrl]" alt="image" title="image" style="width: auto; height: 100%;">
then it works.

Even using a timer on the dialog (and then immediately turning it off) that sets the image source, everything works.

I attach a small example

Greetings

Rocco

Uploaded files:
  • You need to login to have access to uploads.

@roccocogliano the image object does not exist until the Dialog is completely shown. So please try this instead:

SetVar [imgUrl] "https://upload.wikimedia.org/wikipedia/commons/b/b0/European_grey_wolf_in_Prague_zoo_2.jpg"
OpenDialog "dlgImg"
Wait 200
  SetObjectAttribute "Image2" "src" "[imgUrl]"
EndWait

Regards.

 

It works and is the simplest and most elegant solution.
Thanks so much @luishp

luishp has reacted to this post.
luishp