- Add-Type -AssemblyName System.Windows.Forms
-
- $form = New-Object System.Windows.Forms.Form
- $form.Text = '双击查询'
- $Form.FormBorderStyle = "FixedToolWindow"
- $form.StartPosition = 'CenterScreen'
- $form.Font = New-Object System.Drawing.Font("微软雅黑", 10, [Drawing.FontStyle]::Bold)
- $form.ClientSize = '160, 260'
-
- $listBox = New-Object System.Windows.Forms.Listbox
- $listBox.Size = '160,260'
- $listBox.SelectionMode = 'MultiExtended'
- $listBox.DataSource = '张三', '李四', '王五', '赵六'
- $form.Controls.Add($listBox)
-
- $Script:selectedItems = $null
-
- $listBox.add_DoubleClick({
- if($listBox.SelectedItems.Count -ne 1){ return }
- $Script:selectedItems = $listBox.SelectedItems
- $form.Close()
- })
- $listBox.add_MouseDown({
- if($_.Button -ne 'Middle'){ return }
- $Script:selectedItems = $listBox.SelectedItems
- $form.Close()
- })
-
- $result = $form.ShowDialog()
-
-
- $Script:selectedItems
复制代码
|