我有一个PowerShell函数,如果我使用消息框向用户提供反馈,它可以正常工作。但是我想将该函数添加到一个类中。类方法可以正常工作,除了这行代码:
[system.windows.forms.messagebox]::show("The folder path does contain the right parameters.")
它一直给我报错:
Unable to find type: [System.Windows.Forms.Messagebox]
我在网上尝试了所有能找到的方法。我创建了一个非常简单的类,如下所示,它将在ISE中显示消息框,但如果我在PowerShell窗口中运行它,则不会显示消息框。我只是不知道如何找出原因。
class test {
[void]ok() {
Add-Type -AssemblyName "System.Windows.Form"
[void][System.Windows.Forms.Messagebox]::Show("This works in ISE but not powershell window")
}
}
$e = [test]::new()
$e.ok()
我相信这个问题有一个简单的答案,但我不知道是什么。
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Form")
时会发生什么? - undefined