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.
User avatar
BlaaaBlaaaBlaaa
Posts: 10
Joined: Sat Oct 31, 2015 5:06 am

Childform + Background Window

Post by BlaaaBlaaaBlaaa » Sun Nov 01, 2015 9:30 am

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
Joined: Wed Oct 08, 2014 6:02 am

Re: Childform + Background Window

Post by dan.potter » Sun Nov 01, 2015 11:16 am

Turn on STA mode. The tab control would work better for this imo.

User avatar
jvierra
Posts: 13810
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Childform + Background Window

Post by jvierra » Sun Nov 01, 2015 11:22 am

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 68 times

User avatar
BlaaaBlaaaBlaaa
Posts: 10
Joined: Sat Oct 31, 2015 5:06 am

Re: Childform + Background Window

Post by BlaaaBlaaaBlaaa » Mon Nov 02, 2015 2:32 am

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 1754 times
2.png
2.png (29.39 KiB) Viewed 1754 times
3.png
3.png (34.09 KiB) Viewed 1754 times

User avatar
BlaaaBlaaaBlaaa
Posts: 10
Joined: Sat Oct 31, 2015 5:06 am

Re: Childform + Background Window

Post by BlaaaBlaaaBlaaa » Mon Nov 02, 2015 2:34 am

As you can see here each new window is opened "above" the previous one:
4.png
4.png (56.41 KiB) Viewed 1753 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 1753 times

User avatar
jvierra
Posts: 13810
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Childform + Background Window

Post by jvierra » Mon Nov 02, 2015 2:41 am

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
BlaaaBlaaaBlaaa
Posts: 10
Joined: Sat Oct 31, 2015 5:06 am

Re: Childform + Background Window

Post by BlaaaBlaaaBlaaa » Mon Nov 02, 2015 2:47 am

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?

User avatar
jvierra
Posts: 13810
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Childform + Background Window

Post by jvierra » Mon Nov 02, 2015 2:57 am

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
BlaaaBlaaaBlaaa
Posts: 10
Joined: Sat Oct 31, 2015 5:06 am

Re: Childform + Background Window

Post by BlaaaBlaaaBlaaa » Mon Nov 02, 2015 3:05 am

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?

User avatar
jvierra
Posts: 13810
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Childform + Background Window

Post by jvierra » Mon Nov 02, 2015 3:16 am

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.

Locked