2014-12-02 70 views
1

我試圖在PowerShell窗體中使用jpgs按鈕圖像。我想這樣的代碼:Powershell按鈕圖像

#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 

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

的腳本拋出一個錯誤: 找不到類型[System.Controls.Image]:確保被加載包含此類型的程序集。

我試圖使用腳本中的另一個程序集來計算這一個: [void] [reflection.assembly] :: Load('System.Windows.Forms,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089')

我卡在版本,文化和PublicKeyToken(我開始在Powershell Studio中的腳本,但我正在完成它在Notepad ++中)。我怎樣才能最好地獲得這些信息?

謝謝。

回答

1

你選了一個很酷的語言來做.Net開發!!這有點困難,因爲只有很少的文件可以幫忙。

而不是使用System.Controls.Image,儘量爲System.Drawing.Image:

Add-Type -Assembly System.Drawing 
$image = [System.Drawing.Image]::FromFile("C:\users\Administrator\Desktop\Avengers.jpg") 
$button.Image = $image 
+0

謝謝,再次。這一次,我沒有等五個小時問......:/ 你不是在開玩笑說文檔。 – 2014-12-02 06:32:55

+0

我想再次表示感謝。我最後的CS50項目已經完成了,如果沒有你的幫助,我會掙扎得更多。謝謝。 – 2014-12-06 00:55:51