DriveLetter ComboBox 未正确填充
DriveLetter ComboBox not populating correctly
我正在创建一个显示当前 unused/unassigned 盘符的 GUI 脚本。
虽然该功能正常工作(ECHO 按钮将正确的字母写入 PS),但 ComboBox 由单个字母填充(见图)。有人可以向我解释我做错了什么吗?
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Test'
$form.Size = New-Object System.Drawing.Size(280,400)
$form.StartPosition = 'Manual'
$form.Location = '10,10'
$form.Topmost = $true
$button = New-Object System.Windows.Forms.Button
$button.Size = New-Object System.Drawing.Size(50,20)
$button.Location = New-Object System.Drawing.Size(20,20)
$button.Text = "ECHO"
$button.Add_Click($button_click)
$comboBox1 = New-Object System.Windows.Forms.ComboBox
$comboBox1.Location = New-Object System.Drawing.Point(80, 55)
$comboBox1.Size = New-Object System.Drawing.Size(98, 10)
$ComboBox1.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList;
$AllLetters = 67..90 | ForEach-Object {[char]$_ + ":"}
$UsedLetters = Get-WmiObject Win32_LogicalDisk | Select -Expand DeviceID
$FreeLetters = $AllLetters | Where-Object {$UsedLetters -notcontains $_}
ForEach ($Letter in $FreeLetters) { $comboBox1.Items.Add($Drives) }
$button_click = {Write-Host ($FreeLetters)}
$form.Controls.AddRange(@($button, $combobox1))
$form.ShowDialog()
在这一行中:
ForEach ($Letter in $FreeLetters) { $comboBox1.Items.Add($Drives) }
将$Drives
更改为$Letter
我正在创建一个显示当前 unused/unassigned 盘符的 GUI 脚本。 虽然该功能正常工作(ECHO 按钮将正确的字母写入 PS),但 ComboBox 由单个字母填充(见图)。有人可以向我解释我做错了什么吗?
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Test'
$form.Size = New-Object System.Drawing.Size(280,400)
$form.StartPosition = 'Manual'
$form.Location = '10,10'
$form.Topmost = $true
$button = New-Object System.Windows.Forms.Button
$button.Size = New-Object System.Drawing.Size(50,20)
$button.Location = New-Object System.Drawing.Size(20,20)
$button.Text = "ECHO"
$button.Add_Click($button_click)
$comboBox1 = New-Object System.Windows.Forms.ComboBox
$comboBox1.Location = New-Object System.Drawing.Point(80, 55)
$comboBox1.Size = New-Object System.Drawing.Size(98, 10)
$ComboBox1.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList;
$AllLetters = 67..90 | ForEach-Object {[char]$_ + ":"}
$UsedLetters = Get-WmiObject Win32_LogicalDisk | Select -Expand DeviceID
$FreeLetters = $AllLetters | Where-Object {$UsedLetters -notcontains $_}
ForEach ($Letter in $FreeLetters) { $comboBox1.Items.Add($Drives) }
$button_click = {Write-Host ($FreeLetters)}
$form.Controls.AddRange(@($button, $combobox1))
$form.ShowDialog()
在这一行中:
ForEach ($Letter in $FreeLetters) { $comboBox1.Items.Add($Drives) }
将$Drives
更改为$Letter