Help with Center Screen location

Jan 15, 2013 at 9:08 PM

Hey new to powershell and ShowUI (great app btw got referenced in "windows powershell for developers"


Anyways playing around with the sample codes a bit trying to get a feel for it. I can't figure out how to get the box in the center of the screen...Am I missing something obvious.


Import-Module ShowUI 
$info = uniformgrid -ControlName "Get-SourceAndDesitnation" -Columns 2 -Width 700  -WindowStartupLocation CenterScreen{
    Label "Source";        TextBox -Name "Source" 18
    Label "Destination"; TextBox -Name "Destination" John 
    Label "Last Name";  TextBox -Name "LastName" Smith
    button "Ok" -IsDefault -On_Click {
        Get-ParentControl | 
            Set-UIValue -passThru | 
} -show

Jan 15, 2013 at 9:18 PM
Edited Jan 16, 2013 at 10:02 PM

You need to specify the window in order to specify the window startup location. Use the new-window command around what you have there. (I'm on my phone, or I'd write it out).

Jan 16, 2013 at 10:55 PM

Something like this:

Import-Module ShowUI 
$info = Window -Width 300 -Height 200 -WindowStartupLocation CenterScreen {
   Grid -Rows "*","Auto" -Margin 5 {
      UniformGrid -Margin 5 -Columns 2 {
         Label "Source";       TextBox -Name "Source" 18
         Label "Destination";  TextBox -Name "Destination" John 
         Label "Last Name";    TextBox -Name "LastName" Smith
      button "Ok" -HorizontalAlignment Right -Row 2 -MinWidth 80 -IsDefault -On_Click {
         Set-UIValue -UI $window -Passthru | Close-Control
} -Show

I refined a few things in the layout because I can never resist tweaking, but the main thing is:

  1. Wrapped it all in a Window so you can set the WindowStartupLocation
  2. Make sure the call to Set-UIValue sets the window or the immediate child (in this case, I used the automatic $window variable).
  3. Because I was calling Set-UIValue on the window, I need to remove the ControlName property on the nested child control, or else I have to call Set-UIValue on that ...
Jan 17, 2013 at 6:03 PM

Many thanks!!!