Monday, May 10, 2010

WPK Snippets

I have been experimenting with the WPK module from the PowerShell PowerPack. This module enables you to easily write user interfaces within PowerShell. Think PrimalForms but with less code and staying within one IDE. The hard part of writing the UI in WPK is knowing all the methods and properties associated with a particular object. I find searching MSDN for the members very helpful. As I use the different objects (controls), I will share my findings. Up first is the New-FolderBrowserDialog. These examples are ready to be cut and pasted into PowerShell ISE.
Import-Module WPK
New-Window -Name "WPK" -Title "WPK Snippets" -Width 400 -Height 100 -Show {
New-Grid -Rows 28,28 -Columns 75,300* {
New-TextBlock -Text "Folder Path:" -Row 1 -Column 0 -Margin 3
New-TextBox -Name txtUserName -Width 300 -Row 1 -Column 1 -Margin 3
New-Button -Content "Folder" -Name btnFolder -Row 0 -Column 1 -Margin 3 -Width 300 -On_Click {
$obj = New-FolderBrowserDialog -RootFolder "MyComputer"
$obj.ShowDialog()
$txtUserName = $Window | Get-ChildControl txtUserName
$txtUserName.Text = $obj.SelectedPath }
}
}

You should see something similar to the following:


Clicking on the button brings up the familiar "Browse For Folder" Dialog box.


Select a folder and the path is placed in the appropriate textbox.


Enjoy!

5 comments:

John J. Kavanagh said...

Thanks

Wes Stahler said...

You are welcome!

Anonymous said...

Rip Blu-ray for Mac with Blu-ray Ripper for Mac, snow Leopard included.- Free Download and have a try.
Ultimate Blu-ray video converter is actually an 3-in-one software including Blu-ray Ripper, DVD Ripper and Video Converter.

Blu-ray ripper enables you directly rip and convert your Blu-ray movies and general DVDs, even the protected DVDs and Blu-ray DVDs into other popular audio and video formats.

レディースバッグ said...

レディースファッション
水着
ワンピース
チュニック
レディースバッグ
水着通販
水着販売
アウター
ジャケット
ブレザー
パーカー
コート
スプリングコート
トレンチコート
ダウンジャケット
レザージャケット
ブルゾン
ジャンパー
ルームウェア
マジコン
R4 Card
R4
R4i
R4 SDHC
R4i SDHC
R4 cards
R4i ds
R4 ds card
R4i 3ds
R4i gold
Acekard 2i
R4 DS
ds r4
R4DS
Thank you for the information that provided.

Texas hold em online said...

This is really very informative site and all your articles are hot as hell, lots of useful stuff. One thing I just want to say is that your FatBeard's Adventures in PowerShell Blog is so perfect to me.
--------------------------
Our website: Holdem Poker Playing