【发布时间】:2021-03-16 04:58:24
【问题描述】:
我正在 PowerShell 中编写我的第一个子表单。当我编写代码时,一切都会完美地启动。当我通过窗口中的 x 关闭子表单然后重新打开它时,我收到错误:
异常设置“可见”:“无法访问已处置的对象。 对象名称:‘表格’。” 在行:5 字符:5 $ExampleForm.visible = $true ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : 未指定: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting
我的代码如下:
function TestFunction
{
$ExampleForm.enabled = $true
$ExampleForm.visible = $true
}
$Form = New-Object system.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(1050,425)
$form.MaximizeBox = $false
$Form.StartPosition = "CenterScreen"
$Form.FormBorderStyle = 'Fixed3D'
$Form.Text = "Test Form"
$ExampleForm = New-Object system.Windows.Forms.Form
$ExampleForm.Size = New-Object System.Drawing.Size(550,425)
$ExampleForm.MaximizeBox = $false
$ExampleForm.StartPosition = "CenterScreen"
$ExampleForm.FormBorderStyle = 'Fixed3D'
$ExampleForm.Text = "Example"
$ExampleForm.Visible = $False
$TestButton = new-object System.Windows.Forms.Button
$TestButton.Location = new-object system.drawing.size(401,140)
$TestButton.Size = new-object system.drawing.size(80,50)
$TestButton.Text = "Test"
$TestButton.Add_Click({TestFunction})
$TestButton.TabIndex = 33
$Form.Controls.Add($TestButton)
$Form.ShowDialog()
我做错了什么???
【问题讨论】:
-
单击 X 关闭窗口并释放底层资源。您每次都需要创建一个新表单:-)
-
感谢这解决了我的问题!!!
标签: powershell subform