Advertisement
Combreal

flexList.ps1

Dec 22nd, 2022 (edited)
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
  2. [reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
  3.  
  4. $form = New-Object Windows.Forms.Form
  5. $form.text = "FlexList"
  6. $form.ClientSize = New-Object System.Drawing.Size(300,270)
  7. $form.ShowIcon = $false
  8. $form.FormBorderStyle = 'Fixed3D'
  9. $form.MaximizeBox = $false
  10.  
  11. $textfield = New-Object Windows.Forms.TextBox
  12. $textfield.Location = New-Object Drawing.Point 50,30
  13. $textfield.Size = New-Object Drawing.Point 200,30
  14.  
  15. $buttonAdd = New-Object Windows.Forms.Button
  16. $buttonAdd.text = "Add user"
  17. $buttonAdd.Location = New-Object Drawing.Point 100,60
  18.  
  19. $label = New-Object Windows.Forms.Label
  20. $label.Location = New-Object Drawing.Point 50,120
  21. $label.Size = New-Object Drawing.Point 200,15
  22. $label.text = "Users list :"
  23.  
  24. $listbox = New-Object System.Windows.Forms.ListBox
  25. $listbox.Location = New-Object System.Drawing.Size(50,140)
  26. $listbox.Size = New-Object System.Drawing.Size(200,30)
  27. $listbox.Height = 80
  28.  
  29. $buttonRemove = New-Object Windows.Forms.Button
  30. $buttonRemove.text = "Remove selected user"
  31. $buttonRemove.Location = New-Object Drawing.Point 100,220
  32. $buttonRemove.enabled = $false
  33.  
  34.  
  35. $buttonAdd.add_click({
  36.     If ($textfield.text.Length -ne 0) {
  37.         [void] $listbox.Items.Add($textfield.text)
  38.         $textfield.text = ""
  39.         $textfield.Focus()
  40.         $form.refresh()
  41.     }
  42. })
  43.  
  44. $buttonRemove.add_click({
  45.     $listbox.Items.Remove($listbox.SelectedItem)
  46.     If ($listbox.Items.Count -eq 0) {
  47.         $buttonRemove.enabled = $false
  48.         $textfield.Focus()
  49.         $form.refresh()
  50.     }
  51. })
  52.  
  53. $listbox.add_SelectedIndexChanged({
  54.     $buttonRemove.enabled = $true
  55.     $form.refresh()
  56. })
  57.  
  58. $form.controls.add($buttonAdd)
  59. $form.controls.add($buttonRemove)
  60. $form.controls.add($label)
  61. $form.controls.add($textfield)
  62. $form.controls.add($listbox)
  63. $form.ShowDialog()| Out-Null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement