由另一个表单事件触发的 PowerShell 表单事件

由另一个表单事件触发的 PowerShell 表单事件

我已经创建了一个表单(在 PowerShell Studio 中),我想知道是否可以查看哪个事件触发了另一个事件?示例

$button1_Click = {
   $combobox1.Text = 'This is a test'
}
$combobox1_SelectedIndexChanged = {
   Write-Host "I was triggered by button1!" #Is this possible?
}

非常感谢您的帮助!

答案1

谢谢EBGreen谢谢你的帮助建议!

$button1_Click = {
    $global:buttonClicked = $true
    $combobox1.Text = 'This is a test'
}

$combobox1_SelectedIndexChanged = {
    If ($buttonClicked -eq $true)
    {
        Write-Host "I was triggered by button1!"
    }
    Else
    {
        Write-Host "I was triggered by user action!"
    }
    $global:buttonClicked = $false
}

相关内容