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.
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
bhnuser
Posts: 48
Last visit: Tue Nov 21, 2023 10:33 pm

Change picture with a Buttonclick

Post 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
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Change picture with a Buttonclick

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Change picture with a Buttonclick

Post by jvierra »

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

$picturebox1.Image = [System.Drawing.Image]::FromFile($filename)
User avatar
bhnuser
Posts: 48
Last visit: Tue Nov 21, 2023 10:33 pm

Re: Change picture with a Buttonclick

Post 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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Change picture with a Buttonclick

Post 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
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked