I came across a Microsoft IronPython post showing code displaying a Windows form. I copied and pasted the IronPython code into the PowerShell ISE (Integrated Scripting Environment) then:
- Did an Add-Type on Systems.Windows.Forms
- Added some dollar signs ‘$’
- Changed ‘new’ to New-Object
The form is up and running. Clicking on the button adds one to a counter and displays it in the title bar.
A Non-Binary Deployment
Cool thing, if you have Windows 7 installed, you have PowerShell installed. You can copy and paste this code straight away into the PowerShell console and it will work.
You could even email this snippet and as long as the receiver has PowerShell installed it would work.
The Code
Add-Type -AssemblyName System.Windows.Forms $f = New-Object System.Windows.Forms.Form $b = New-Object System.Windows.Forms.Button $f.StartPosition = "CenterScreen" $b.Text = "Hello World" $b.Location = New-Object System.Drawing.Point(250,100) $f.Width = 561 $f.Controls.Add($b) $count = 0 $b.add_click({ $f.Text = ($count += 1) }) $f.ShowDialog() | Out-Null
{ 3 comments… read them below or add one }
Really Doug? C’mon …. ARE YOU READY FOR SOME JAVASCRIPT MOTHER $&%*#!?
How to avoid full namespace qualification over and over again?
System.Windows.Forms.Button.blAH BLAH
Good question. I tried this but no luck.