Change picture with a Buttonclick

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
User avatar
bhnuser
Posts: 20
Joined: Fri Apr 06, 2018 7:35 am

Change picture with a Buttonclick

Post by bhnuser » Tue Jan 08, 2019 6:14 am

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

User avatar
davidc
Posts: 5593
Joined: Thu Aug 18, 2011 4:56 am

Re: Change picture with a Buttonclick

Post by davidc » Tue Jan 08, 2019 8:00 am

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 13019
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Change picture with a Buttonclick

Post by jvierra » Tue Jan 08, 2019 8:28 am

Just assign a new image to the control in the buttonclick.

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

User avatar
bhnuser
Posts: 20
Joined: Fri Apr 06, 2018 7:35 am

Re: Change picture with a Buttonclick

Post by bhnuser » Fri Jan 11, 2019 2:57 am

jvierra wrote:
Tue Jan 08, 2019 8: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?

User avatar
jvierra
Posts: 13019
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Change picture with a Buttonclick

Post by jvierra » Fri Jan 11, 2019 3:09 am

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

Post Reply