Page 1 of 1

Change picture with a Buttonclick

Posted: Tue Jan 08, 2019 5:14 am
by bhnuser
Hello everybody,

i have a short question. Is it possible to change a picture in a picturebox when i click a button?
My problem is, that i can show one picture over the properties and dont know how to change it in the script.
Btw.: I attached the picture to my PowerShell Studio Project. The Project should be build and released on some computers.

Best regards

Re: Change picture with a Buttonclick

Posted: Tue Jan 08, 2019 7:00 am
by davidc
[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]

Re: Change picture with a Buttonclick

Posted: Tue Jan 08, 2019 7:28 am
by jvierra
Just assign a new image to the control in the buttonclick.

$picturebox1.Image = [System.Drawing.Image]::FromFile($filename)

Re: Change picture with a Buttonclick

Posted: Fri Jan 11, 2019 1:57 am
by bhnuser
jvierra wrote: Tue Jan 08, 2019 7:28 am Just assign a new image to the control in the buttonclick.

$picturebox1.Image = [System.Drawing.Image]::FromFile($filename)
Thank you for the helpful question. But now is my question how i can add image-files to my project so i can open them in a imagebox from every computer. I tried to add them in my setting over files / folder but how i can open them?

Re: Change picture with a Buttonclick

Posted: Fri Jan 11, 2019 2:09 am
by jvierra
I don't understand what you are asking. The code above opens an image file into a PictureBox control.

You have two methods to do this. One is to copy the files into the project and distribute the files with the project and two is to add the images to an ImageList control at design time and they will be encoded and embedded in the script.

For more instructions see the following:

PictureBox
ImageList