在我的脚本中,我要求用户将值添加到我将在脚本的其余部分使用的列表中。我目前使用的是:
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(350,380)
$form.Padding = New-Object System.Windows.Forms.Padding(20,100,20,20)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Multiline = $true
$textBox.ScrollBars = "Vertical"
$textBox.ReadOnly = $true
$textBox.Dock = [System.Windows.Forms.DockStyle]::Fill
$form.Controls.Add($textBox)
$inputLabel = New-Object System.Windows.Forms.Label
$inputLabel.Text = "Doc:"
$inputLabel.Size = New-Object System.Drawing.Size(50,20)
$inputLabel.Location = New-Object System.Drawing.Point(20,22)
$form.Controls.Add($inputLabel)
$addDocButton = New-Object System.Windows.Forms.Button
$addDocButton.Text = "Add to project"
$addDocButton.Size = New-Object System.Drawing.Size(85,23)
$addDocButton.Location = New-Object System.Drawing.Point(220,20)
$docs = @()
$addDocButton.Add_Click({
  $docs += $inputBox.Text
  $textBox.AppendText("Document added to project: $docs`r`n")
  $inputBox.Clear()
})
$form.Controls.Add($addDocButton)
$inputBox = New-Object System.Windows.Forms.TextBox
$inputBox.Size = New-Object System.Drawing.Size(140,20)
$inputBox.Location = New-Object System.Drawing.Point(70,20)
$form.Controls.Add($inputBox)
$form.ShowDialog()
但每次单击按钮时,列表都会被重写。“+=”不应该附加值而不是重写吗?