Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell找不到类型[System.Windows.Forms.KeyEventHandler]_Powershell_User Interface_.net Assembly - Fatal编程技术网

Powershell找不到类型[System.Windows.Forms.KeyEventHandler]

Powershell找不到类型[System.Windows.Forms.KeyEventHandler],powershell,user-interface,.net-assembly,Powershell,User Interface,.net Assembly,这可能是一个非常简单的问题,但我完全迷路了,寻找答案也没有什么帮助 我有一些powershell代码来显示带有文本框的简单GUI。某些文本框允许用户按Enter键运行按钮\单击代码。当我尝试运行PS1脚本时,会出现以下错误: Unable to find type [System.Windows.Forms.KeyEventHandler]. Make sure that the assembly that contains this type is loaded.At C:\Scripts\G

这可能是一个非常简单的问题,但我完全迷路了,寻找答案也没有什么帮助

我有一些powershell代码来显示带有文本框的简单GUI。某些文本框允许用户按Enter键运行按钮\单击代码。当我尝试运行PS1脚本时,会出现以下错误:

Unable to find type [System.Windows.Forms.KeyEventHandler].
Make sure that the assembly that contains this type is loaded.At C:\Scripts\GUI-Testing.ps1:161 char:1

$TestVar=[System.Windows.Forms.KeyEventHandler]
CategoryInfo          : InvalidOperation: (System.Windows.Forms.KeyEventHandler:TypeName)
FullyQualifiedErrorId : TypeNotFound
奇怪的是,如果我关闭GUI,然后重新运行脚本,我不会出现
找不到类型
错误,按Enter键可以正常工作


认为我有答案,我尝试使用
[void][reflection.assembly]::Load('System.Windows.Forms.KeyEventHandler')
,这会导致此错误
异常,使用“1”参数调用“Load”:“无法加载文件或程序集'System.Windows.Forms.KeyEventHandler'或其依赖项之一。[FileNotFoundException]

确保在脚本顶部加载以下程序集:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
如果它仍然不起作用,您可以执行以下操作:

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({
    if ($_.KeyCode -eq "Enter") 
    {    
        #Write Code Here
    }
})

我应该已经用
[void][reflection.assembly]::Load('System.Windows.Forms,Version=2.0.0.0,Culture=neutral')加载了它。
谢谢,我正在编写其他示例,程序集是在按Enter键变量的情况下加载的。powershell会抱怨的。现在powershell很高兴了!谢谢!