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.
This topic is 4 years and 10 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
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Displaying a modal form

Post by Lembasts »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Displaying a modal form

Post by jvierra »

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: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Displaying a modal form

Post by Lembasts »

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?)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Displaying a modal form

Post by jvierra »

That is what modal means and all Windows in PowerShell are modal. They are actually all modal dialog Windows.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Displaying a modal form

Post by Lembasts »

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: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Displaying a modal form

Post by Lembasts »

I think the term is 'Secure desktop' form.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Displaying a modal form

Post by Lembasts »

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: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Displaying a modal form

Post by Lembasts »

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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Displaying a modal form

Post by jvierra »

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: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Displaying a modal form

Post by Lembasts »

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...
This topic is 4 years and 10 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