Childform + Background Window

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 8 years and 4 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
User avatar
sFULkRpS1635685113
Posts: 10
Last visit: Fri Oct 29, 2021 12:28 pm

Childform + Background Window

Post by sFULkRpS1635685113 »

Hi guys,

I just started using Powershell Studio so please excuse me if got anything wrong or if I am missing something.

I just started to create a new GUI for a script by creating a new project. I would like to create a "Start" Window where you can choose a Topic f.e. Active Directory or Exchange and afterwards you are guided to a new window with scripts belonging to that topic.

Is it possible to keep everything in 1 window? I did it this way right now which opens a new window which kinda works but is not as nice as I would like to have it:

$btn_ActiveDirectory_Click={
#TODO: Place custom script here
Call-ActiveDirectory_psf
}

If this is not possible: Can I somehow close the first window in the same step as opening the new window?
I use the following for a "quit" button but I can not combine it with the call-AD - the window still is opened in the background:
$form_start.Close()


Last question for now:
I exported the script with my current status to ps1 and to .exe as well. When I run the script it already looks really nice but besides the GUI I created a Shell window is opened. Is there a way to just have the GUI showing up?

Thanks a lot in advance and have a great day!!
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Childform + Background Window

Post by dan.potter »

Turn on STA mode. The tab control would work better for this imo.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Childform + Background Window

Post by jvierra »

In a standard Form in PowerShell we are limited to one Window at a time because we can only use modal dialog, However there is a way around this and that is to use an MDI form.

Here is a demo or an MDI form that allows many Windows wit management.
Attachments
Demo-MDIForm.ps1
Run this to see MDI form.
(6.72 KiB) Downloaded 154 times
User avatar
sFULkRpS1635685113
Posts: 10
Last visit: Fri Oct 29, 2021 12:28 pm

Re: Childform + Background Window

Post by sFULkRpS1635685113 »

Hi Guys,

Thanks for the fast responses. However I think that is not really what I am looking for. I created some screenshots to describe the issue a little bit better:

I want to create a "menu" where people can browse to the topic they would like to use a script:
1.png
1.png (25.66 KiB) Viewed 3310 times
2.png
2.png (29.39 KiB) Viewed 3310 times
3.png
3.png (34.09 KiB) Viewed 3310 times
User avatar
sFULkRpS1635685113
Posts: 10
Last visit: Fri Oct 29, 2021 12:28 pm

Re: Childform + Background Window

Post by sFULkRpS1635685113 »

As you can see here each new window is opened "above" the previous one:
4.png
4.png (56.41 KiB) Viewed 3309 times
The Quit button should close the whole script/tool for me - but it can only close the current window.

The last question i mentioned was regarding the Shell window in the background as you can see here:
5.png
5.png (87.98 KiB) Viewed 3309 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Childform + Background Window

Post by jvierra »

I posted an MDI form that will behave more like you want. Did you look at it? Al windows open in the main and can be forced to fill the client area. A close button on an MDI child can terminate the script.

You can also just call "exit" in your close event.
User avatar
sFULkRpS1635685113
Posts: 10
Last visit: Fri Oct 29, 2021 12:28 pm

Re: Childform + Background Window

Post by sFULkRpS1635685113 »

Hi jvierra,

Yes I just looked into it and you might be right. I will try to set this up for my script later today and then comeback to you.
At the first look it confused me a bit but it could be working.
Thanks for now :)

Do you have any idea regarding the Shell window in the background? Is there a solution or do I have to get used to this?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Childform + Background Window

Post by jvierra »

BlaaaBlaaaBlaaa wrote:Hi jvierra,

Do you have any idea regarding the Shell window in the background? Is there a solution or do I have to get used to this?
I do not understand the question.

To exit the application use this:
[environment]::Exit(99)

The 99 is just the exit code to be returned. It can be anything you like.
User avatar
sFULkRpS1635685113
Posts: 10
Last visit: Fri Oct 29, 2021 12:28 pm

Re: Childform + Background Window

Post by sFULkRpS1635685113 »

Ok I will try to clarify that as well - sorry for my bad explanation.

When you run the .ps1 or .exe the GUI starts and everything looks fine. However in the background you can see a Powershell Window (the last screenshot i posted). I would like normal users to use the script as well and they might get confused by that "shell" window or close it which aborts the script.

Is there a way to hide this window or to start it minimized in the background?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Childform + Background Window

Post by jvierra »

If you hide the parent the child will also become hidden.
This is a design issue. Normally we would make the parent or control Window full screen and the children would be dialogs. THe kind of Window you are trying to build is not possible in PowerShell and it is contrary to Windows UI design.

The parent window cannot confuse the user because it cannot be activated.
This topic is 8 years and 4 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