[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)|out-null
[System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)|out-null
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = “Test”
$objForm.Size = New-Object System.Drawing.Size(1000,700)
$objForm.StartPosition = “CenterScreen”
$objForm.MaximizeBox = $false
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq “Escape”) {$objForm.Close()}})
Function CreateCheckBox($CheckBoxName,$LocationX, $LocationY,$SizeX,$SizeY,$Text,$color = “Blue”)
{
$CheckBoxName = New-Object System.Windows.Forms.CheckBox
$CheckBoxName.Location = New-Object System.Drawing.Size($LocationX,$LocationX)
$CheckBoxName.Size = New-Object System.Drawing.Size($SizeX,$SizeY)
$CheckBoxName.Text = $Text
$CheckBoxName.ForeColor = $color
$objForm.Controls.Add($CheckBoxName)
return $CheckBoxName
}
&CreateCheckBox($Test,420,30,500,20,”Test”,’Blue’)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
还是自己搞定了.
CLS
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")|out-null
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")|out-null
$Global:objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Test"
$objForm.Size = New-Object System.Drawing.Size(1000,700)
$objForm.StartPosition = "CenterScreen"
$objForm.MaximizeBox = $false
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close()}})
function Global:CreateNewCheckBox($Name,$LocationX, $LocationY,$SizeX,$SizeY,$Text,$color)
{
$ExpName = ('$Global:'+$Name + ' = New-Object System.Windows.Forms.CheckBox')
$ExpLocation = '$'+ $Name + '.Location = New-Object System.Drawing.Size('+$LocationX+','+$LocationY+')'
$ExpSize = '$'+ $Name + '.Size = New-Object System.Drawing.Size('+$SizeX+','+$SizeY+')'
$ExpText = '$'+ $Name + '.Text = '+ '$Text'
$ExpColor = '$'+ $Name + '.ForeColor = ' +'$color'
$Load = '$objForm.Controls.Add('+'$'+$Name+')'
$return = 'return ' + '$'+ $Name
write-host $ExpName
Write-Host $ExpLocation
Write-Host $ExpSize
Write-Host $ExpText
Write-Host $ExpColor
Write-Host $Load
# Write-Host $return
Invoke-Expression $ExpName
Invoke-Expression $ExpLocation
Invoke-Expression $ExpSize
Invoke-Expression $ExpText
Invoke-Expression $ExpColor
Invoke-Expression $Load
#Invoke-Expression $return
}
CreateNewCheckBox TestX 420 20 500 20 "Tester..X." Red
CreateNewCheckBox TestY 420 40 500 20 "Tester2..Y." Blue
CreateNewCheckBox Testz 420 60 500 20 "Tester2..Z." Green
Write-Host $TestX.Text
$Testz.ForeColor = 'Gray'
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()