[英]How to close a winform with powershell?
I have created a winform:我创建了一个winform:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
function more {
$MoreTools = New-Object system.Windows.Forms.Form
$MoreTools.ClientSize = New-Object System.Drawing.Point(903,473)
$MoreTools.text = "$title002"
$MoreTools.TopMost = $false
$MoreTools.icon = "ressources\pictures\ico.ico"
$MoreTools.StartPosition = 'CenterScreen'
$ButtonB = New-Object system.Windows.Forms.Button
$ButtonB.text = "$button007"
$ButtonB.width = 128
$ButtonB.height = 25
$ButtonB.location = New-Object System.Drawing.Point(387,350)
$ButtonB.Font = New-Object System.Drawing.Font('Segoe UI',10)
$MoreTools.controls.AddRange(@($ButtonB))
$ButtonB.Add_Enter({
$MoreTools.Close
})
[void]$MoreTools.ShowDialog()
}
more
exit
When I use exit or $MoreTools.Close it doesn't want to close.当我使用 exit 或 $MoreTools.Close 时,它不想关闭。 So, how to close the form or where is the error?那么,如何关闭表单或错误在哪里?
Thanks谢谢
JJB JJB
Use add_Click()
method rather than Add_Enter()
on a button;在按钮上使用add_Click()
方法而不是Add_Enter()
; moreover, .Close
does not mean .Close()
:此外, .Close
并不意味着.Close()
:
$ButtonB.Add_Click({
$MoreTools.Close();
$MoreTools.Dispose(); # facultative
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.