I’d like to Create a couple of Buttons by using a Hashtable.
The problem is that the creating and access of dynamic Variables don’t work.
Here my script:
$ButtonList = @{
'NumPad1' = "Enter"
'NumPad2' = "ESC"
}
function WriteButtonName ($sBName){
Write-Host $sBName
}
$x_pos= 35
$form = New-Object System.Windows.Forms.Form
foreach($b in $ButtonList.GetEnumerator()){
$Name = $($b.Name)
$Value = $($b.Value)
New-Variable -Name $Name #-Value New-Object System.Windows.Forms.Button
$(get-variable -Name $Name) = New-Object System.Windows.Forms.Button
(get-variable -Name $Name).Location = New-Object System.Drawing.Size($x_pos,35)
(get-variable -Name $Name).Size = New-Object System.Drawing.Size(120,23)
(get-variable -Name $Name).Text = $Value
(get-variable -Name $Name).Add_Click({WriteButtonName -sBName $Name })
$x_pos += 130
}
Where are my misstake? Thanks.