I have the Following Script:
$ButtonList = @{
'NumPad1' = "Enter"
'NumPad2' = "ESC"
}
function WriteButtonName ($sBName){
Write-Host $sBName
}
$x_pos= 35
$v= get-variable -Name "x_pos"
$($v.Name)
$form = New-Object System.Windows.Forms.Form
foreach($b in $ButtonList.GetEnumerator()){
$Name = $($b.Name)
$Value = $($b.Value)
$Name
$Value
Remove-Variable -Name $Name
New-Variable -Name $Name #-Value New-Object System.Windows.Forms.Button
(get-variable -Name $Name).Value = New-Object System.Windows.Forms.Button
(get-variable -Name $Name).Value.Location = New-Object System.Drawing.Size($x_pos,35)
(get-variable -Name $Name).Value.Size = New-Object System.Drawing.Size(120,23)
(get-variable -Name $Name).Value.Text = $Value
(get-variable -Name $Name).Value.Add_Click({WriteButtonName -sBName (get-variable -Name $Name).Value.Text })
$x_pos += 130
$form.Controls.Add((get-variable -Name $Name).Value)
}
$form.showdialog()
This Scipt Create 2 Buttons, and by Clicking they return Something. But Because the ‘$Name’ ist stored just the last Name I’d get the Name from the Varible where the first Button is stored.
How can in Reference to the Variable where the Clicking button ist stored?
Thanks.