Building a GUI in ISE

Does anyone have any information on getting started in building a GUI in PS ISE?

Thank you,

Zach,
Welcome to the forum.

Wow. Have you at least bothered to try to search for an answer before you came here to ask someone else to search for you? :wink:

https://www.google.com/search?q=Powershell+GUI&oq=Powershell+GUI&aqs=chrome..69i57j69i65l3.3584j0j1&sourceid=chrome&ie=UTF-8

1 Like

There are, as usual, multiple ways to skin the proverbial cat. If you want to use a tool like VSCode, here is a good article:

For me personally, I just used the MS samples and played around with building them manually:

1 Like

I realized I had this old GUI template in my repo. Perhaps it will be of some use:

function GUI { 
    $form = New-Object System.Windows.Forms.Form
    $form.Text = 'My Test Gui'
    $form.FormBorderStyle = 'Fixed3D'
    $form.MaximizeBox = $false
    $form.Size = New-Object System.Drawing.Size(1205,450)
    $form.StartPosition = 'CenterScreen'
    $form.Font = New-Object System.Drawing.Font("Arial", 13)

    $lbl1 = New-Object System.Windows.Forms.Label
        $lbl1.Location = New-Object System.Drawing.Point(55, 30)
        $lbl1.AutoSize = $true
        $lbl1.Text = "This is a test label"
        $form.Controls.Add($lbl1)

    $inp1 = New-Object System.Windows.Forms.TextBox
        $inp1.Location = New-Object System.Drawing.Point(215, 30)
        $inp1.Size = New-Object System.Drawing.Size(210, 20)
        $inp1.TextAlign = 'Center'
        $inp1.MaxLength = 15
        $inp1.Text = "This is an input"
        $form.Controls.Add($inp1)

    $cmbo1 = New-Object System.Windows.Forms.ComboBox
        $cmbo1.Location = New-Object System.Drawing.Point(445, 30)
        $cmbo1.Size = New-Object System.Drawing.Size(140, 20)
        foreach ($a in "This is a combo") {$cmbo1.Items.Add($a) | Out-Null}
        $cmbo1.SelectedIndex = 0
        $cmbo1.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
        $form.Controls.Add($cmbo1)

    $cmbo1.add_SelectedValueChanged{
        [System.Windows.MessageBox]::Show("You chose $($cmbo1.Text)!")
    }

    $check1 = New-Object System.Windows.Forms.CheckBox
        $check1.Location = New-Object System.Drawing.Point(595,30)
        $check1.Size = New-Object System.Drawing.Size(130, 20)
        $check1.Font = New-Object System.Drawing.Font("Arial", 9)
        $check1.Text = "This is a check box"
        $check1.Add_CheckStateChanged({
            if ($check1.Checked) {
                [System.Windows.MessageBox]::Show("You checked me!")
            } else {
                [System.Windows.MessageBox]::Show("You unchecked me!")
            }
        })
        $form.Controls.Add($check1)

    $inpWithRegex = New-Object System.Windows.Forms.TextBox
        $inpWithRegex.Location = New-Object System.Drawing.Point(730, 30)
        $inpWithRegex.Size = New-Object System.Drawing.Size(170, 20)
        $inpWithRegex.TextAlign = 'Center'
        $inpWithRegex.MaxLength = 25
        $inpWithRegex.Text = "This input uses regex!"
        $inpWithRegex.add_TextChanged({
            if($inpWithRegex.Text -match '[A-Z]') {
                $inpWithRegex.Text = $inpWithRegex.Text -replace '[A-Z]'
                    if($inpWithRegex.Text.Length -gt 0) {
                        $inpWithRegex.Focus()
                        $inpWithRegex.SelectionStart = $inpWithRegex.Text.Length
                    }
            }
        })
        $form.Controls.Add($inpWithRegex)

    $btn1 = New-Object System.Windows.Forms.Button
        $btn1.Location = New-Object System.Drawing.Point(910,30)
        $btn1.Size = New-Object System.Drawing.Size(200, 50)
        $btn1.Text = "This is a button"
        $btn1.Add_Click({       
            [System.Windows.MessageBox]::Show("You clicked my button!")
        })
        $form.controls.Add($btn1)

    $datePicker1 = New-Object System.Windows.Forms.DateTimePicker
    $datePicker1.Location = New-Object System.Drawing.Point(10, 90)
    $datePicker1.Size = New-Object System.Drawing.Size(300, 50)
    $form.Controls.Add($datePicker1)

    $progressBar1 = New-Object System.Windows.Forms.ProgressBar
    $progressBar1.Location = New-Object System.Drawing.Point(320, 90)
    $progressBar1.Size = New-Object System.Drawing.Size(300, 50)
    $progressBar1.Text = "I'm a progress bar!"
    $form.Controls.Add($progressBar1)

    $radio1 = New-Object System.Windows.Forms.RadioButton
    $radio1.Location = New-Object System.Drawing.Point(640, 90)
    $radio1.Size = New-Object System.Drawing.Size(180, 50)
    $radio1.Text = "I'm a radio button!"
    $form.Controls.Add($radio1)

    $grid1 = New-Object System.Windows.Forms.DataGridView
        $grid1.Name = "This is a grid"
        $grid1.Location = '10,190'
        $grid1.Size = '1170,200'
        $grid1.ReadOnly = $true
        $grid1.ColumnHeadersVisible = $true
        $grid1.ColumnCount = 10
            $grid1.Columns[0].Name = "Column 1"
            $grid1.Columns[1].Name = "Column 2"
            $grid1.Columns[2].Name = "Column 3"
            $grid1.Columns[3].Name = "Column 4"
            $grid1.Columns[4].Name = "Column 5"
            $grid1.Columns[5].Name = "Column 6"
            $grid1.Columns[6].Name = "Column 7"
            $grid1.Columns[7].Name = "Column 8"
            $grid1.Columns[8].Name = "Column 9"
            $grid1.Columns[9].Name = "Column 10"
        $grid1.ColumnHeadersHeightSizeMode = 'AutoSize'
        $grid1.Columns | ForEach-Object {
            $_.AutoSizeMode = [System.Windows.Forms.DataGridViewAutoSizeColumnMode]::AllCells
        }

        $form.Controls.Add($grid1)


    $result = $form.ShowDialog()
}

GUI

Thank you Sir! That will give me something to review and get started with.