Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

multiple groupboxs with autosize

$
0
0

Based on the needs of this little project, i have a small Powershell GUI that generates a Groupbox object for all my webservers.  Inside each server groupbox i generate a groupbox for each site, that contains 2 radio buttons, and a textbox (small control function).

 because the number of the sites on the servers can vary, i need to have the server groupbox autosize to contain all of the potential sites.  problem i am having is the first, second and third server group boxes generate with proper spacing between them.  The 4th one wants to segregate itself further away and i cannot figure out why.

i have attempted to put in some write-host points to see what it is doing.  i am attempting to use the .bottom point of the previous groupbox as a reference to start the next one.  as far as i can tell even though the autosized groupbox varies in size, it always shows the height of the box being only 100.  

Any ideas?

here is my code.

$servers @=(server1, server2, server3, server4)

$Y = 20 $X = 0 $h = 20 $b = 0 $cv = 0 $Yoffset = 0 foreach ($srv in $servers) { If ($cv -lt 2){ $X = 10 $Y += $Yoffset } else { $X = 300 $Y = 0 # $Yoffset = 0 } $srv $X $Y $Yoffset New-variable -name "$srv" -value $(new-object System.Windows.Forms.GroupBox -Property @{ AutoSize = $true Location = New-Object System.Drawing.Point ($X,($Y + $Yoffset)) Text = $srv ForeColor = "Blue" }) $Form.Controls.Add($(Get-Variable "$srv" -ValueOnly)) $srv write-host "top: " $(Get-Variable "$srv" -ValueOnly).Top write-host "bottom: " $(Get-Variable "$srv" -ValueOnly).Bottom write-host "Height: " $(Get-Variable "$srv" -ValueOnly).height $Yoffset = $(Get-Variable "$srv" -ValueOnly).Bottom if ($cv -eq 2){ $Yoffset = 20} $cDir = "\\"+$srv + $basepath $exclude =@("aspnet_client","tinybox2") $contents = Get-ChildItem -Path $cDir -Exclude $exclude | where {$_.PSIsContainer} $i=20 foreach ($dir in $contents){ $dir.name New-variable -name "$dir.name" -value $(new-object System.Windows.Forms.GroupBox -Property @{ Location = New-Object System.Drawing.Point (10,$i) Autosize = $true Size = New-Object System.Drawing.Size(250,50) Text = $dir.name }) $(Get-Variable "$srv" -ValueOnly).Controls.Add($(Get-Variable "$dir.name" -ValueOnly)) $rbN = New-object System.Windows.Forms.RadioButton $rbN.Location = New-object System.Drawing.Size (10,15) $rbN.Size = New-object System.Drawing.Size (40,25) $rbN.Text = "On" $(Get-Variable "$dir.name" -ValueOnly).Controls.Add($rbN) $rbF = New-object System.Windows.Forms.RadioButton $rbF.Location = New-object System.Drawing.Size (55,15) $rbF.Size = New-object System.Drawing.Size (50,25) $rbF.Text = "Off" $(Get-Variable "$dir.name" -ValueOnly).Controls.Add($rbF) New-variable -name "stat_$dir.name" -value $(new-object System.Windows.Forms.Textbox -Property @{ Name = 'SSvar' Location = New-Object System.Drawing.Size(110,15) Size = New-Object System.Drawing.Size(100,23) Text = "Off" }) $(Get-Variable "$dir.name" -ValueOnly).Controls.Add($(Get-Variable "stat_$dir.name" -ValueOnly)) checkSiteStatus $dir.name $i += 65 } $cv += 1 if ($cv -ge 4) { $cv = 0} }



Viewing all articles
Browse latest Browse all 15028

Trending Articles