Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
- [reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
- $form = New-Object Windows.Forms.Form
- $form.text = "FlexList"
- $form.ClientSize = New-Object System.Drawing.Size(300,270)
- $form.ShowIcon = $false
- $form.FormBorderStyle = 'Fixed3D'
- $form.MaximizeBox = $false
- $textfield = New-Object Windows.Forms.TextBox
- $textfield.Location = New-Object Drawing.Point 50,30
- $textfield.Size = New-Object Drawing.Point 200,30
- $buttonAdd = New-Object Windows.Forms.Button
- $buttonAdd.text = "Add user"
- $buttonAdd.Location = New-Object Drawing.Point 100,60
- $label = New-Object Windows.Forms.Label
- $label.Location = New-Object Drawing.Point 50,120
- $label.Size = New-Object Drawing.Point 200,15
- $label.text = "Users list :"
- $listbox = New-Object System.Windows.Forms.ListBox
- $listbox.Location = New-Object System.Drawing.Size(50,140)
- $listbox.Size = New-Object System.Drawing.Size(200,30)
- $listbox.Height = 80
- $buttonRemove = New-Object Windows.Forms.Button
- $buttonRemove.text = "Remove selected user"
- $buttonRemove.Location = New-Object Drawing.Point 100,220
- $buttonRemove.enabled = $false
- $buttonAdd.add_click({
- If ($textfield.text.Length -ne 0) {
- [void] $listbox.Items.Add($textfield.text)
- $textfield.text = ""
- $textfield.Focus()
- $form.refresh()
- }
- })
- $buttonRemove.add_click({
- $listbox.Items.Remove($listbox.SelectedItem)
- If ($listbox.Items.Count -eq 0) {
- $buttonRemove.enabled = $false
- $textfield.Focus()
- $form.refresh()
- }
- })
- $listbox.add_SelectedIndexChanged({
- $buttonRemove.enabled = $true
- $form.refresh()
- })
- $form.controls.add($buttonAdd)
- $form.controls.add($buttonRemove)
- $form.controls.add($label)
- $form.controls.add($textfield)
- $form.controls.add($listbox)
- $form.ShowDialog()| Out-Null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement