Listbox in Powershell GUI

Made a powershell GUI with a listbox. Trying to select an item from the listbox, click a button, and show a messagebox.

$formHome = New-Object system.Windows.Forms.Form $formHome.ClientSize = '571,276' $formHome.text = "Home Screen" $formHome.TopMost = $false $items = New-Object system.Windows.Forms.ListBox $items.text = "listBox" $items.width = 264 $items.height = 211 $items.location = New-Object System.Drawing.Point(20,46) $items.Sorted = $true $items.ScrollAlwaysVisible = $true $btnGetItem = New-Object system.Windows.Forms.Button $btnGetItem.text = "OK" $btnGetItem.width = 120 $btnGetItem.height = 30 $btnGetItem.location = New-Object System.Drawing.Point(318,169) $btnGetItem.Font = 'Microsoft Sans Serif,10' $People = New-Object system.Windows.Forms.Label $People.text = "People:" $People.AutoSize = $true $People.width = 25 $People.height = 10 $People.location = New-Object System.Drawing.Point(25,19) $People.Font = 'Microsoft Sans Serif,10' $formHome.controls.AddRange(@($items,$btnGetItem,$People)) $items.Items.Add("Phone Number") $items.Items.Add("Address") $items.Items.Add("Name") foreach ($item in $items.SelectedItems) { if ($item -eq "Phone Number") { $btnGetItem.add_Click({ [System.Windows.Forms.MessageBox]::Show("You seleceted Phone Number") }) } if ($script -eq "Address") { $btnGetItem.add_Click({ [System.Windows.Forms.MessageBox]::Show("You seleceted Address") }) } if ($script -eq "Name") { $btnGetItem.add_Click({ [System.Windows.Forms.MessageBox]::Show("You seleceted Name") }) } } $formHome.ShowDialog() 

Don’t know what I’m doing wrong?

submitted by /u/DolphinRapeIsBad
[link] [comments]

Leave a Reply