0
我在這裏掙扎。使用Powershell GUI +刷新
把這個示例代碼:
[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
我不能爲我的生命弄清楚爲什麼當我輸入文本框,然後單擊OKButton(合併)沒有happns。它應該輸出到$輸出,或者至少,這就是我想要發生的事情。
我只是試圖讓代碼接受文本框的輸入並將其輸出到名爲$ output的標籤形式。
我已經得到它的工作原理,當我把輸入文本框並按'合併',它會輸出到Powershell_ISE控制檯,但只有在窗口關閉並運行一秒後時間(當我按'合併'時不會刷新$輸出標籤,只有在關閉程序時才輸出)
請幫忙!
謝謝
謝謝。這真的有幫助! – obious 2012-04-19 21:25:28