Skip to content

Instantly share code, notes, and snippets.

@foofoodog
Created July 8, 2012 13:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foofoodog/3071000 to your computer and use it in GitHub Desktop.
Save foofoodog/3071000 to your computer and use it in GitHub Desktop.
powershell-winform
New-Module -ScriptBlock {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$form = New-Object System.Windows.Forms.Form
$grid = New-Object System.Windows.Forms.PropertyGrid
$grid.Dock = [System.Windows.Forms.DockStyle]::Fill
$button = New-Object System.Windows.Forms.Button
$button.Text = "OK"
$button.Dock = [System.Windows.Forms.DockStyle]::Bottom
$form.Controls.Add($button)
$form.Controls.Add($grid)
# Item to return, not null for OK
$item = $null
$button.add_Click(
{
# Set the return item
$item = $grid.SelectedObject
$form.Close()
}
)
function Edit-Object($obj) {
# Item to return, null for Cancel
$item = $null
$grid.SelectedObject = $obj
$form.ShowDialog() | Out-Null
return $item
}
Export-ModuleMember -Function Edit-Object
} | Out-Null
cls
$obj = New-Object System.Windows.Forms.Button
$ret = (Edit-Object $obj)
if ($ret) {
$ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment