- Add-Type -AssemblyName System.Windows.Forms
-
- [system.Windows.forms.form]$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.Dock = 'Fill'
- $listBox.SelectionMode = 'MultiExtended'
- $listBox.DataSource = '张三', '李四', '王五', '赵六'
- $form.Controls.Add($listBox)
- $form.add_FormClosing( {
- param($oSender, $oArgs)
- $oArgs.Cancel = $listBox.SelectedItems.Count -eq 0
- $Script:selectedItems = $listBox.SelectedItems
- })
-
- $result = $form.ShowDialog()
- $Script:selectedItems
复制代码 必须选择至少一个对象才能退出窗口; |