ato*_*son 3 variables powershell user-interface button
我正在学习Powershell并尝试创建一个类似于此处示例的GUI界面.
但是,当我按原样运行时,$x从未定义过.知道我可能做错了吗?我知道它与以下内容有关:
$OKButton.Add_Click({$x=$objListBox.SelectedItem;$objForm.Close()})
因为如果我将其更改为:
$OKButton.Add_Click({Write-Host "worked";$objForm.Close()})
它确实回来了worked.
您的actionblock在单独的本地范围内运行.要修改全局(会话范围)变量,请使用scope-modifier($global:varname).例如:
$OKButton.Add_Click({$global:x=$objListBox.SelectedItem;$objForm.Close()})
Run Code Online (Sandbox Code Playgroud)
有关Technet范围的更多信息- about_Scopes(或Get-Help about_scopes在PowerShell中编写)