Created
July 8, 2012 13:52
-
-
Save foofoodog/3071000 to your computer and use it in GitHub Desktop.
powershell-winform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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