Forum Discussion
KickAss1996
May 14, 2020Copper Contributor
Run sub command under other line
Hello to everybody! I need some help with ps script that i'm writing these days. in my script i created a list and when the script start to run the list showen and you can choose from it. my quest...
Manfred101
May 16, 2020Iron Contributor
KickAss1996 Ckeck out the snippet below, just edit the $ScriptToExecute to whatever you want to do!
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(400,200)
$Form.Width = 400
$Form.Height = 500
$form.MaximizeBox = $false
$Form.StartPosition = "CenterScreen"
$Form.FormBorderStyle = 'Fixed3D'
$Form.Text = "My Application"
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)
$listBox.Height = 80
[void] $listBox.Items.Add('Phone 10')
[void] $listBox.Items.Add('Phone 11')
[void] $listBox.Items.Add('Phone 12')
[void] $listBox.Items.Add('Phone 13')
[void] $listBox.Items.Add('Phone 14')
[void] $listBox.Items.Add('Phone 15')
[void] $listBox.Items.Add('Phone 16')
$form.Controls.Add($listBox)
$ScriptToExecute = {
[System.Windows.MessageBox]::Show($listBox.SelectedItem)
}
$Okbutton = New-Object System.Windows.Forms.Button
$Okbutton.Location = New-Object System.Drawing.Size(140,200)
$Okbutton.Size = New-Object System.Drawing.Size(120,30)
$Okbutton.Text = "Ok"
$Okbutton.Add_Click($ScriptToExecute)
$Form.Controls.Add($Okbutton)
$Form.ShowDialog()
Goodluck!
Grtz, Manfred de Laat