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
User interface 使用Powershell GUI+;刷新_User Interface_Powershell_Powershell 2.0 - Fatal编程技术网

User interface 使用Powershell GUI+;刷新

User interface 使用Powershell GUI+;刷新,user-interface,powershell,powershell-2.0,User Interface,Powershell,Powershell 2.0,我在这里挣扎 以以下示例代码为例: [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Data En

我在这里挣扎

以以下示例代码为例:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$objForm = New-Object System.Windows.Forms.Form 
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(500,400) 
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") 
    {$output1=$objTextBox.Text}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 
    {$objForm.Close()}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(100,90)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Merge"
$OKButton.Add_Click({$output=$objTextBox.Text})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(300,90)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(160,20) 
$objLabel.Size = New-Object System.Drawing.Size(280,20) 
$objLabel.Text = "Please enter the target machine: "
$objForm.Controls.Add($objLabel) 

$output = new-object System.Windows.forms.label
$output.location = new-object System.drawing.size(30, 140)
$output.size = New-Object System.Drawing.Size(300,300) 
$objform.controls.add($output)

$objTextBox = New-Object System.Windows.Forms.TextBox 
$objTextBox.Location = New-Object System.Drawing.Size(115,40) 
$objTextBox.Size = New-Object System.Drawing.Size(260,20) 
$objForm.Controls.Add($objTextBox) 

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
$output
我一辈子都搞不懂为什么当我在框中输入文本并单击OK按钮(合并)时什么都没发生。它应该被输出到$output,或者至少,这是我想要的

我只是想让代码接受文本框的输入并将其输出到名为$output的标签表单

我的工作原理是,当我将输入输入输入到文本框并按“合并”时,它会将其输出到Powershell_ISE控制台,但只有在窗口关闭并再次运行后(当我按“合并”时,它不会刷新$output标签,当我关闭程序时,它才会输出)

请帮忙

谢谢

修改

$OKButton.Add_Click({$output=$objTextBox.Text})


非常感谢。这真的很有帮助!
$OKButton.Add_Click({$output.text=$objTextBox.Text})