[英]How to close a powershell gui windows form after the button is clicked?
i have a script which created a small windows gui form with buttons depending on the scenarios; 我有一个脚本,可以根据情况使用按钮创建一个小的Windows gui表单;
-> on clicking, these buttons open respective files on remote file shares;following is the code; ->单击时,这些按钮将打开远程文件共享上的相应文件;以下是代码;
$run.Add_Click({Invoke-Expression "Powershell \\Fileshare\$Random_File.Doc"}.GetNewClosure())
-> my issue is eventhough after the click the file opens ; ->我的问题仍然是在单击文件后打开; the form still hangs arround in the back ground;
表格仍然悬挂在背景中; I want to know how to close it(and even better if i can close whole powershell too) ;
我想知道如何关闭它(如果我也能关闭整个Powershell,那就更好了); i tried to embed ";exit" inside invoke but it gave errors , is there any other way to do it?
我试图将“; exit”嵌入到调用中,但是它给出了错误,还有其他方法吗?
Please ask me if any questions or clarifications required. 请问我是否需要任何问题或澄清。
I suspect Invoke-Item \\\\fileshare\\$file
will work much better than running new PowerShell for any document you want to open. 我怀疑
Invoke-Item \\\\fileshare\\$file
会比为您要打开的任何文档运行新的PowerShell更好。
To close the form you can add $this.Parent (?).Close() or just reference $form variable - that also should work: 要关闭表单,您可以添加$ this.Parent(?)。Close()或仅引用$ form变量-这也应该起作用:
$form = New-Object System.Windows.Forms.Form
$run = New-Object System.Windows.Forms.Button -Property @{
Location = New-Object System.Drawing.Point -Property @{
X = 0
Y = 0
}
Text = 'Run'
}
$run.Add_Click({
Invoke-Item C:\Windows
$form.Close()
})
$form.Controls.Add($run)
$form.ShowDialog()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.