Powershell form.acceptbutton多个动作

时间:2018-10-11 15:35:07

标签: powershell

如何在Powershell GUI中使用Enter键执行2种不同的操作?

我有一个Powershell表单,该表单具有使用自动完成功能的下拉菜单。我对Enter键执行了操作以运行按钮。

$xyz.AutoCompleteSource = 'CustomSource' $xyz.AutoCompleteMode='SuggestAppend' $xyz.AutoCompleteCustomSource=$autocomplete "x", "y", "z" | % {$xyz.AutoCompleteCustomSource.AddRange($_) }

$Form.AcceptButton = $GoButton

在文本框中键入内容时,我希望能够按Enter接受下拉菜单中突出显示的选项,然后再次按Enter运行我的处理程序$ GoButton。

这可能吗?

1 个答案:

答案 0 :(得分:2)

已解决:

我没有使用“ New-Object System.Windows.Forms.TextBox”,而是创建了一个“ New-Object System.Windows.Forms.Combobox”组合框。

这允许第一次按下“ enter”来选择突出显示的选项,第二次按下“ enter”来运行我的处理程序。