Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2010-12-01
If you are doing this as a script, you must have given yourself the permission execute scripts.
To start, you must load the library that holds the classes that are used for GUI programming. Remember, you cannot do a line break here. I only do it so that the whole line will visible.
[System.Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
(Again, the above code is one single line.)
If you are unsure about versions and public keys, check your assembly folder in your Windows folder. If you right click on an assembly, and open the Properties dialog. There you highlight and copy the assambly information.
When the assembly is loaded, you can create a Form. This code will give it a caption and a size.
$myForm=New-Object Windows.Forms.Form $myForm.Size=New-Object Drawing.Size(360,200) $myForm.Text="Using Windows GUI from PowerShell"
The next thing I want to do, is to add a text label and a text input fileld on my form. I will position the text field under my label field.
$someLabel=New-Object Windows.Forms.Label $someLabel.AutoSize=$true $someLabel.Text="Enter your name:" $someLabel.Location=New-Object Drawing.Point(10,10) $someField=New-Object Windows.Forms.TextBox $someField.Size=New-Object Drawing.Size(300,16) $someField.Location=New-Object Drawing.Point(10,30) $myForm.Controls.Add($someLabel) $myForm.Controls.Add($someField)
To show this form, call the ShowDialog function of the form object.
$myForm.ShowDialog()
This is the result:
The next thing to do, is to react on user input.
Categories: PowerShell
Tags: PowerShell
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
You ll want to start off by unzipping and copying the contents of the qForms. be amazed by how little actual JavaScript was needed in order to get the forms. Create a directory off the root of your web server to store the qForms API.