OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Pwoershell Creating Button by Hastable with dynamic Varible

  • Thread starter Thread starter TheRob87
  • Start date Start date
T

TheRob87

Guest
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:

Code:
$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.
<p>I'd like to Create a couple of Buttons by using a Hashtable.</p>
<p>The problem is that the creating and access of dynamic Variables don't work.</p>
<p>Here my script:</p>
<pre><code>$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

}
</code></pre>
<p>Where are my misstake? Thanks.</p>
Continue reading...
 

Latest posts

Top