Just as the title said. I'm currently stuck trying to access a variable outside of an event handler. This is the code
param ([int[]]$coordinates, [string]$label, [string[]]$options)
$newGroup = New-Object System.Windows.Forms.GroupBox
$newGroup.Location = New-Object System.Drawing.Point($coordinates[0], $coordinates[1])
$checkbox = New-Object System.Windows.Forms.CheckBox
$checkbox.Appearance = [System.Windows.Forms.Appearance]::Normal
$checkbox.Text = $label
$checkbox.AutoSize = $true
$radioPanel = New-Object System.Windows.Forms.Panel
$radioPanel.Location = New-Object System.Drawing.Point(10, 10)
$radioPanel.AutoSize = $true
$radioPanel.Enabled = $false
function Initialize-toggler {
param([System.Windows.Forms.Panel]$radioPanel)
$checkbox.Add_CheckedChanged({
param($checkbox)
Write-Host "panel.enabled: $($radioPanel)"
Write-Host "checkbox.checkedState: $($checkbox.CheckState)"
if($checkbox.CheckState -eq $true){
$radioPanel.Enabled = $true
} else {
$radioPanel.Enabled = $false
}
})
}
Initialize-toggler -radioPanel $radioPanel
///
$newGroup.Controls.Add($checkbox)
$newGroup.Controls.Add($radioPanel)
return $newGroup
}
on the $checkbox.Add_CheckedChanged() i tried to access variable $radioPanel and disable it based on the state of $checkbox. However $radioPanel returns error whenever i called it inside the event handler. I tried putting it inside the event handler as a parameter but that doesn't work. the event handler only accepts $checkbox variable as its param.
So again, how do i access $radioPanel inside the event handler $checkbox.Add_CheckedChanged()?