GUI help

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 months and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
JaredPSS
Posts: 1
Last visit: Mon Mar 27, 2023 11:45 am

GUI help

Post by JaredPSS »

Hello! I am trying to create an app that will have several buttons on the main page. Right now I have two buttons, and when you click the first button "Network" it makes a panel visible which has 2 more buttons. I was manually positioning them, but they overlap my panel buttons when they show up. Ill add a screenshot that helps explain it better. Thanks for any help!

# Create a new form object
$form = New-Object System.Windows.Forms.Form

# Set the form's properties
$form.Text = "Main Window"
$form.StartPosition = "CenterScreen"
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D
$form.AutoSize = $true

# Create a button object called "Network" that toggles the additional buttons when clicked
$button1A = New-Object System.Windows.Forms.Button
$button1A.Location = New-Object System.Drawing.Point(20, 20)
$button1A.Size = New-Object System.Drawing.Size(100, 30)
$button1A.Text = "Network"
$form.Controls.Add($button1A)


# Create a panel object to hold the additional buttons
$panel = New-Object System.Windows.Forms.Panel
$panel.Location = New-Object System.Drawing.Point(20, 60)
$panel.Size = New-Object System.Drawing.Size(100, 60)
$panel.Visible = $false
$form.Controls.Add($panel)

# Create two new button objects within the panel object
$button1 = New-Object System.Windows.Forms.Button
$button1.Location = New-Object System.Drawing.Point(0, 0)
$button1.Size = New-Object System.Drawing.Size(100, 30)
$button1.Text = "Button 1"
$panel.Controls.Add($button1)

$button2 = New-Object System.Windows.Forms.Button
$button2.Location = New-Object System.Drawing.Point(0, 30)
$button2.Size = New-Object System.Drawing.Size(100, 30)
$button2.Text = "Button 2"
$panel.Controls.Add($button2)

# Add an event handler to toggle the visibility of the panel when the button is clicked
$button1A.Add_Click({
if ($panel.Visible)
{
$panel.Visible = $false
}
else
{
$panel.Visible = $true
}
})

# Show the form
$form.ShowDialog() > $null

function Main {
<#
.SYNOPSIS
The Main function starts the project application.

.PARAMETER Commandline
$Commandline contains the complete argument string passed to the script packager executable.

.NOTES
Use this function to initialize your script and to call GUI forms.

.NOTES
To get the console output in the Packager (Forms Engine) use:
$ConsoleOutput (Type: System.Collections.ArrayList)
#>
Param ([String]$Commandline)

#--------------------------------------------------------------------------
#TODO: Add initialization script here (Load modules and check requirements)


#--------------------------------------------------------------------------

$script:ExitCode = 0 #Set the exit code for the Packager
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI help

Post by jvierra »

The code is not helpful as it just displays a form. The "Main" function will never be called.

It would be better if you posted the PSF file as an attachment.
This topic is 11 months and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked