Displaying Nested Form

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 1 year and 6 months 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
davivolo
Posts: 5
Last visit: Fri Oct 14, 2022 8:04 am
Has voted: 1 time

Displaying Nested Form

Post by davivolo »

Hello!

There is probably a better way to do this but I am attempting to integrate a please wait... dialogue box (without a button) into my GUI so that when my restore script is running it shows this box until it has finished. I am doing this right now by using

Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Label = New-Object System.Windows.Forms.Label

I was curious if there is a way to embed this form inside the GUI whitespace because right now it opens in a separate window. If there is a better way to do this I am very open to that as well but I am fairly new to powershell so I apologize for my shortcomings here.

Full code is:

Code: Select all

Add-Type -AssemblyName System.Windows.Forms
	$Form = New-Object system.Windows.Forms.Form
	$Label = New-Object System.Windows.Forms.Label
	$Form.Controls.Add($Label)
	$Label.Text = "Backing up files, please wait..."
	$Label.AutoSize = $True
	$Form.Visible = $True
	$Form.Update()
	##script runs here##
	$Form.Close()
	
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Displaying Nested Form

Post by jvierra »

I was curious if there is a way to embed this form inside the GUI whitespace because right now it opens in a separate window. If there is a better way to do this I am very open to that as well but I am fairly new to powershell so I apologize for my shortcomings here.
The simple answer is no. You can just create a label the size you want and display it over the form client area and then remove it when your task completes.
davivolo
Posts: 5
Last visit: Fri Oct 14, 2022 8:04 am
Has voted: 1 time

Re: Displaying Nested Form

Post by davivolo »

Is there an example somewhere of a label being used in this fashion? I have tried to configure it but seem to be having issues using it in this manner. Thanks!
davivolo
Posts: 5
Last visit: Fri Oct 14, 2022 8:04 am
Has voted: 1 time

Re: Displaying Nested Form

Post by davivolo »

jvierra wrote: Thu Sep 08, 2022 4:00 pm
I was curious if there is a way to embed this form inside the GUI whitespace because right now it opens in a separate window. If there is a better way to do this I am very open to that as well but I am fairly new to powershell so I apologize for my shortcomings here.
The simple answer is no. You can just create a label the size you want and display it over the form client area and then remove it when your task completes.
Is there an example somewhere of a label being used in this fashion? I have tried to configure it but seem to be having issues using it in this manner. Thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Displaying Nested Form

Post by jvierra »

Just plunk a label in the middle of your form and set it to hidden. When you want to set it to visible and then hide it when your script is done.

[b}$label1.Visible = [$true/$false][/b]
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Displaying Nested Form

Post by jvierra »

Here .i s an article that will help you learn how to use Forms, Controls and the label control.

https://info.sapien.com/index.php/guis/ ... el-control
This topic is 1 year and 6 months 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