Tuesday, May 18, 2010

WPK Snippets

Here is another WPK snippet for you. This one will demonstrate how to use New-Slider and New-Ellipse. Assuming that you the PowerPack Modules installed, you should be able to cut and paste the following:
Import-Module WPK           
New-Window -Name "WPK" -Title "WPK Snippets" -Width 250 -Height 175 -Show {
New-Grid -Rows 28,100 -Columns 200* {
New-TextBox -Name txtSliderValue -Column 0 -Row 1
$fill = [System.Windows.Media.Brushes]::Blue
$stroke = [System.Windows.Media.Brushes]::Black
New-Ellipse -Name oEllipse -Column 0 -Row 2 -Height 100 -Width 100 `
-Fill $fill -Stroke $stroke
New-Slider -Name Slider -Column 0 -Row 0 -Minimum 0 -Maximum 200 `
-IsSnapToTickEnabled -On_ValueChanged {
$txtSliderValue = $window | Get-ChildControl txtSliderValue
$slider = $window | Get-ChildControl Slider
$oEllipse = $window | Get-ChildControl oEllipse
$oEllipse.width = $slider.value
}
}
}
You should see something like the following:


Moving the slider triggers the -On_ValueChanged event.
Moving it around you should see the width of the ellipse change accordingly.


Download the script.

Enjoy!

7 comments:

Josh said...

I have no New-Window in WPK?

PS C:> gcm -Module WPK *window*

CommandType Name
----------- ----
Function New-WindowsFormsHost
Function Show-Window

Wes Stahler said...

Not seen that before Josh. What OS and Framework version are you running?

Josh said...

W7 x64, DN 4.0 RTM

Wes Stahler said...

Do any of the other Modules exhibit similar behavior?

Josh said...

Nope, never had a problem with anything else before.

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.