Displaying a modal 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.
User avatar
Lembasts
Posts: 202
Joined: Thu Mar 15, 2012 9:47 am

Displaying a modal form

Post by Lembasts » Thu May 16, 2019 10:07 pm

Greetings,
I have a single form that I need to display modally.
Google tells me its the showdialog method.
So I put that in my load event and it didnt go modal and the error said it shouldnt be visible.
So I put a $form1.visible = $false before my $form1.showdialog() in my load event and its still not modal.
What bit am I missing please?
Thanks
David

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

Re: Displaying a modal form

Post by jvierra » Fri May 17, 2019 2:51 am

You cannot use "ShowDialog()" after the form is already shown.

All forms in PowerShell are modal. PSS can only build modal forms. Even when using a compiled language a form cannot be changed for modal to modeless or modeless to modal after the from has been created.

Making a modal form hidden (visible = $false) closes the form.

You cannot show a the form from inside any of the forms events.

User avatar
Lembasts
Posts: 202
Joined: Thu Mar 15, 2012 9:47 am

Re: Displaying a modal form

Post by Lembasts » Fri May 17, 2019 6:09 am

In which case I am using the wrong terminology.
I thought modal meant the window is displayed preventing entering anything else anywhere else on the desktop until you deal with the window (like the UAC prompt).
Whats that called and how do I do that (Can it be done?)

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

Re: Displaying a modal form

Post by jvierra » Fri May 17, 2019 11:03 am

That is what modal means and all Windows in PowerShell are modal. They are actually all modal dialog Windows.

User avatar
Lembasts
Posts: 202
Joined: Thu Mar 15, 2012 9:47 am

Re: Displaying a modal form

Post by Lembasts » Sun May 19, 2019 3:41 pm

Well there's something I am still missing.
I compile this form into an exe and launch the exe.
The form displays but I can still interact with the desktop.
What do I need to do so that when the exe is launched, everything goes dark, like a UAC prompt, and wont let me continue or interact with anything until I deal with the form?
Thanks
David

User avatar
Lembasts
Posts: 202
Joined: Thu Mar 15, 2012 9:47 am

Re: Displaying a modal form

Post by Lembasts » Sun May 19, 2019 4:02 pm

I think the term is 'Secure desktop' form.

User avatar
Lembasts
Posts: 202
Joined: Thu Mar 15, 2012 9:47 am

Re: Displaying a modal form

Post by Lembasts » Sun May 19, 2019 6:52 pm

I came up with a solution that will work.
I start a timer when the form loads and if they dont press a specific button on the form within 60 seconds, they will be logged off.

User avatar
Lembasts
Posts: 202
Joined: Thu Mar 15, 2012 9:47 am

Re: Displaying a modal form

Post by Lembasts » Mon May 20, 2019 8:54 pm

So they dont like my timer as people can alt-tab, perhaps launch task manager quickly and kill my task.
So can a window be displayed in secure desktop mode?

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

Re: Displaying a modal form

Post by jvierra » Mon May 20, 2019 11:32 pm

Not with basic PowerShell. You would have to use the Win32 API calls to create a proess modal to the desktop. In windows 10 I do not think this is possible. We used to do it With XP. Allowing this can be a security issue.

User avatar
Lembasts
Posts: 202
Joined: Thu Mar 15, 2012 9:47 am

Re: Displaying a modal form

Post by Lembasts » Tue May 21, 2019 2:30 pm

Thanks.
When I saw this:
https://social.technet.microsoft.com/Fo ... powershell
I decided it was way to hard.
Looks like Im back to the timer thing...

Locked