Floating toolbar

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 3 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
kpro1982
Posts: 6
Last visit: Sat Jan 14, 2023 11:11 pm

Floating toolbar

Post by kpro1982 »

My application is a set of tools that aid in coding using powershell studio gui. When I work in the ide, I want the main window of my app minimized but I want a floating tool bar with important buttons. If I maximize the main app, I want the toolbar to close. What is the best way to accomplish that? At present, I have it set up so that minimizing the main form in my app will open a new form with the buttons that I need. But this set up requires me to manually close the tool bar form before I can give focus back to the main form. I want that to be automatic so that maximizing the main form minimizes the tools form and visa versa. The code for the tool bar is attached.
Attachments
KommandStrip.psf
(74.88 KiB) Downloaded 32 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Floating toolbar

Post by jvierra »

Wow! Is that confusing. I can see why you are stuck. You cannot have two modal dialogs on the screen at the same time and have both active. The last guy up controls everything and the first form can do nothing. PowerShell has only one thread so it can execute only one line of code at a time or one script. Each form is a new script although it is wrapped in a function. When the function exits the form will close and the calling form will now be able to execute code.

Check the Sapien articles for more background on why this happens and some hints as to other ways to accomplish your task.
kpro1982
Posts: 6
Last visit: Sat Jan 14, 2023 11:11 pm

Re: Floating toolbar

Post by kpro1982 »

Thank you for the reply. I appreciate your help as I am obviously very new to powershell studio. As an alternative, I would be happy if closing the tool bar maximized the main form. This code maximizes the main wizard but leaves the tools form visible and dead. Just closing out of the tools form by clicking on the x in the upper right closes the tool window but doesn't maximize the main window. How can I accomplish both in one click: (1) maximize the main form; (2) close the child form.

$buttonX_Click={
Show-Wizard_psf
}
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 20
Been upvoted: 37 times

Re: Floating toolbar

Post by Alexander Riedel »

Disclaimer: I have not looked at your code.
Maybe it would be easier it you split it into two processes? The toolbar launches/activates the main form when closed. The main form terminates the toolbar process when activated. When minimized the main form starts the toolbar process. If there is little to no data exchanged between the two processes, this might make it easier.
Alexander Riedel
SAPIEN Technologies, Inc.
kpro1982
Posts: 6
Last visit: Sat Jan 14, 2023 11:11 pm

Re: Floating toolbar

Post by kpro1982 »

Thank you for the reply. Two processes is a good idea. I'd prefer not to terminate the main process but don't care if the toolbar stays running or closes. It seems that splitting the processes, while a clever solution, would make it more difficult to maintain. I would prefer a strategy in which closing the toolbar closes its form but at the same time maximizes the main form. Isn't there a method by which a form can close itself? Something like: show-myform_psf.Close()
kpro1982
Posts: 6
Last visit: Sat Jan 14, 2023 11:11 pm

Re: Floating toolbar

Post by kpro1982 »

Got it. I was missing the fact that there is a $this variable. The following works. I knew that it had to be simple.
$buttonX_Click={
$this.Parent.hide()
Show-Wizard_psf
}

Thank you both for your help.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 20
Been upvoted: 37 times

Re: Floating toolbar

Post by Alexander Riedel »

:D
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 3 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