我已尝试使用以下代码在ListViewbox中显示输出。但我无法在框中显示任何输出。
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Form"
$Form.TopMost = $true
$Form.Width = 696
$Form.Height = 323
$button2 = New-Object system.windows.Forms.Button
$button2.Text = "Go"
$button2.Width = 60
$button2.Height = 30
$button2.Add_Click({
$listView3.Text = Get-Process | Out-String
})
$button2.location = new-object system.drawing.point(238,70)
$button2.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($button2)
$listView3 = New-Object system.windows.Forms.ListView
$listView3.Text = "listView"
$listView3.Width = 330
$listView3.Height = 600
$listView3.location = new-object system.drawing.point(269,146)
$Form.controls.Add($listView3)
[void]$Form.ShowDialog()
$Form.Dispose()
我还需要在列表框中以表格格式显示输出..提前感谢....
答案 0 :(得分:0)
listview控件的.text
属性不控制显示的内容,您需要添加项目。假设您要在列表中显示进程名称,而不是:
$listView3.Text = Get-Process | Out-String
尝试:
Get-Process | %{$listView3.Items.Add($_.processname)}
要添加子项,您需要执行以下操作:
Get-Process | %{$item = $listView3.Items.Add($_.processname);$item.SubItems.Add($_.Handles)}