3

I'm trying to use jpgs for button images in a Powershell form. I tried this code:

#Add Image to Button
$image = New-Object System.Windows.Controls.Image
$image.Source = "C:\users\Administrator\Desktop\Avengers.jpg"
$image.Stretch = 'Fill'
$button.Content = $image

From: http://learn-powershell.net/2012/10/01/powershell-and-wpf-buttons/

The script is throwing an error: Cannot find type[System.Controls.Image]: Make sure the assembly containing this type is loaded.

I tried to use another assembly from the script to figure this one out: [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')

I'm stuck on version, culture, and PublicKeyToken (I started the script in Powershell Studio, but I'm finishing it in Notepad++). How can I best get this information?

Thank you.

1 Answer 1

6

You picked a cool language to do .Net development in!! It's a bit difficult though, since there is very little documentation to help out.

Instead of using System.Controls.Image, try System.Drawing.Image:

Add-Type -Assembly System.Drawing
$image = [System.Drawing.Image]::FromFile("C:\users\Administrator\Desktop\Avengers.jpg")
$button.Image = $image
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, again. This time, I didn't wait five hours to ask...:/ You're not kidding about the documentation.
I wanted to say thanks again. My final project for CS50 is almost done, and I would've struggled much more without your help. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.