To make a picture stay in the dialog

I created a dialog and added an imagecontrol in it. I upload my picture and checked the case (link) to link the url of the image to the dialog. But when i close my macro after saving it or when i launch the macro, the image in the dialog doesnt show up . When i go back to dialog parameters there is no image in it. I dont undrstand the problem. Is there a way to make the image stay ?

For the image to remain in the Dialogue, insert the image into a spreadsheet in the file.

Example file…
menu em dialogo.ods (311,7,KB)

you put your image in the last sheet “Plan3” but to make it stay in the dialog i don’t see where in the code you did it.

Please upload the file containing the macro you wrote about.
If you created the dialog in the usual way (via BasicIDE), then follow the advice of colleague @schiavinatto - insert the same .jpg picture on some (hidden) sheet of the document - then this picture will not be deleted.

1 Like

If you use SVG image, then it is possible to add the svg definition to the Sub and save it like real file for example to Temporary directory of LibreOffice. And then use this file in Dialog.
It only need double the quotes in String for svg definition in Sub (cSVG). And of course the best is optimalized SVG, save it in InkScape as Optimalized, or I use GitHub - svg/svgo-gui: Node-WebKit based GUI for SVGO

Sub ShowDialog
	rem svg defition with doubled quotes for string -> ""
	const cSvg="<svg version=""1.2"" width=""14.26mm"" height=""7.22mm"" viewBox=""6010 2629 1426 722.00005"" preserveAspectRatio=""xMidYMid"" fill-rule=""evenodd"" xmlns=""http://www.w3.org/2000/svg""><defs class=""EmbeddedBulletChars""><path d=""M.283-.557l.285.278-.285.279-.285-.279z""/><path d=""M.004-.551h.551v.551h-.551z""/><path d=""M.085 0l.209-.361-.209-.362.626.362zm.578-.361l-.512-.296.171.296z""/><path d=""M.984-.361l-.361.361h-.273l.265-.265h-.53v-.192h.53l-.265-.266h.272z""/><path d=""M0 .001l-.012-.019.186-.259-.069-.189.02-.019.017.002.032-.012.013.006.054.123.137-.147.031.012.012-.012.03.021-.074.108-.086.098.088.176-.031.041.008.01-.027.021-.105-.149-.143.223-.045.025-.031-.025-.005-.021.001-.015z""/><path d=""M.139.016c-.05 0-.085-.031-.103-.092l-.016-.154.02-.098.077-.052.052.046.011.086.029.048.359-.345.032-.008.031.022v.06l-.015.041-.4.407-.077.039z""/><path d=""M.397 0c-.088 0-.158-.026-.21-.079-.052-.052-.078-.122-.078-.21s.026-.158.078-.21c.052-.052.122-.079.21-.079.087 0 .158.026.211.079.053.052.079.123.079.21 0 .088-.026.158-.079.21-.053.052-.124.079-.211.079z""/><path d=""M.169-.223l-.093-.038-.04-.092.04-.092.093-.038.09.039.038.091-.037.092-.091.038z""/><path d=""M-.002-.224h.556v-.072h-.556z""/><path d=""M.084-.361c0-.08.028-.148.084-.205.057-.056.125-.084.205-.084.08 0 .147.028.204.084.057.057.085.125.085.205 0 .08-.028.148-.085.204-.057.057-.125.085-.204.085-.08 0-.148-.028-.205-.085-.056-.056-.084-.125-.084-.204z""/></defs><g class=""Page""><g class=""com.sun.star.drawing.ClosedBezierShape""><path class=""BoundingBox"" fill=""none"" d=""M6010 2629h424v722h-424z""/><path fill=""#ff8a17"" d=""M6433 3084c0 48-17 84-53 109s-82 157-150 157c-62 0-115-130-151-152s-59-56-69-101l99-16c6 26 19 44 39 56s46 18 80 18c71 0 106-22 106-65 0-14-4-25-12-34s-19-17-34-23-44-13-86-21c-36-9-60-16-75-21s-27-11-39-18-21-15-29-25-14-21-19-35-7-29-7-46c0-44 17-78 50-101s84-136 147-136c60 0 102 110 132 129s50 50 59 94l-99 13c-5-21-15-36-31-47s-38-16-67-16c-61 0-92 19-92 58 0 13 3 23 10 31s16 15 29 21 39 12 78 21c47 10 79 18 100 27s36 17 48 29 21 24 27 40 9 34 9 54z""/></g><g class=""com.sun.star.drawing.ClosedBezierShape""><path class=""BoundingBox"" fill=""none"" d=""M6465 2630h462v691h-462z""/><path fill=""#8e9001"" d=""M6740 3260l-100 60-175-582 125 92 81 220c6 20 15 51 26 92l7-30 17-62 109-420 96 108z""/></g><g class=""com.sun.star.drawing.ClosedBezierShape""><path class=""BoundingBox"" fill=""none"" d=""M6988 2640h448v681h-448z""/><path fill=""#fe39bd"" d=""M7208 3151c26 0 52-4 77-12s44-17 57-29v-67l-82-13-120-110 250 60 45 167c-25 26-94 118-135 133s-55 40-100 40c-79 0-134-111-177-155s-33-105-33-185-10-142 33-185 97-155 177-155c114 0 194 133 225 218l-94 28c-10-25-91-126-121-126-47 0-86 65-111 94s-38 71-38 125c0 55 13 97 39 127s61 45 108 45z""/></g></g></svg>"
	dim oDoc as object, oDlg as object, oImg as object, fSvg as object, sUrl$, iFile%
	rem save cSVG to real file
	sUrl=CreateUnoService("com.sun.star.util.PathSettings").Temp_writable & "/image4dlg.svg" 'Tools/ Options/ LibreOffice/ Paths -> Temporary files (probably you can use only .Temp)
	iFile=FreeFile
	Open sUrl for Output as #iFile
	Print #iFile, cSVG
	Close #iFile
	rem show dialog
	oDoc=ThisComponent
	oDlg=CreateUnoDialog(DialogLibraries.Standard.Dialog1)
	oImg=oDlg.getControl("ImageControl1")
	oImg.Model.ScaleImage=false
	oImg.Model.ImageUrl=sUrl
	oDlg.execute
End Sub

dialog-with-SVG.ods (14.1 kB)

My image is just a simple jpg