hello
i have stock Multi project form. What i want is to auto - minimize the main form when i minimize child.
but when i do that, child is auto closed. Is there any way to achieve that ?
Problem is that when child is minimized, main form is still shown and its frozen - cannot be used until child is closed.
So at least i want it out of screen
Minimize Form auto closes Child
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.
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.
Re: Minimize Form auto closes Child
Yes. That is a limitation of modal dialogs. Both the main form and the child are modal dialogs. If a form and child are shown and they have a parent child relation then minimizing the main form will minimize the child but minimizing the child will never minimize the parent.
This is by design. The only way to avoid this is to use runspaces or the forms or to create a true main form which cannot easily be done in PowerShell. It is also extremely hard to do in PowerShell Studio as PSS does not provide any mechanism for creating forms that can be launched with the application run command. Even if it could the PowerShell single threaded environment can cause issues with forms run in this way.
This is by design. The only way to avoid this is to use runspaces or the forms or to create a true main form which cannot easily be done in PowerShell. It is also extremely hard to do in PowerShell Studio as PSS does not provide any mechanism for creating forms that can be launched with the application run command. Even if it could the PowerShell single threaded environment can cause issues with forms run in this way.
- daniel kusnir
- Posts: 75
- Last visit: Tue May 23, 2023 10:50 am
Re: Minimize Form auto closes Child
Here is an example of how to accomplish you goal. It works and can be used but requires some careful thought to extend.
- Attachments
-
- ChildTest.zip
- (110.92 KiB) Downloaded 124 times
- daniel kusnir
- Posts: 75
- Last visit: Tue May 23, 2023 10:50 am
Re: Minimize Form auto closes Child
Wow, thanks a lot
so you basically figured it out. And i can now also work with both windows concurrently. You are genius
And if you add this code, you can minimize form without closing the child - simply amazing
so you basically figured it out. And i can now also work with both windows concurrently. You are genius
And if you add this code, you can minimize form without closing the child - simply amazing
- $formChildForm_SizeChanged={
- if ($this.WindowState -eq 'Minimized'){ $parent.WindowState = 'Minimized' }
- elseif ($this.WindowState -eq 'Normal') { $parent.WindowState = 'Normal' }
- }
Re: Minimize Form auto closes Child
No, I knew this and just created a quick demo. It iwll present many new challenges when used like a normal form. First it has no access to the environment of the parent for. That means it cannot see or use any variables that the parent can see.
- daniel kusnir
- Posts: 75
- Last visit: Tue May 23, 2023 10:50 am
Re: Minimize Form auto closes Child
i see.
what about the global properties ? i see e.g OpenFileDialog() is not working just by simply adding it to the child. Is that part of the challenge ?
what about the global properties ? i see e.g OpenFileDialog() is not working just by simply adding it to the child. Is that part of the challenge ?
Re: Minimize Form auto closes Child
There ae no shared global properties.
To use a runspace it is necessary to understand how to work with runspaces. This can be a challenge even for trained programmers. It is much better to design solutions that do not require advanced programming skills and that allow you to leverage PowerShell Studio and forms without pain.
\Most of my experience with those new to PowerShell and WinForms is that they have no training in WinForms and how to design a form. WinForms was designed to solve specific problems in certain ways which can make it very challenging to do things that were not part of the original design intent of MS.
The attached file shows how to get the file dialogs to work in a runspace.
To use a runspace it is necessary to understand how to work with runspaces. This can be a challenge even for trained programmers. It is much better to design solutions that do not require advanced programming skills and that allow you to leverage PowerShell Studio and forms without pain.
\Most of my experience with those new to PowerShell and WinForms is that they have no training in WinForms and how to design a form. WinForms was designed to solve specific problems in certain ways which can make it very challenging to do things that were not part of the original design intent of MS.
The attached file shows how to get the file dialogs to work in a runspace.
- Attachments
-
- ChildTest_1.zip
- (115.14 KiB) Downloaded 125 times
Re: Minimize Form auto closes Child
Here is an example of one way to use arguments and to manage a child form in a separate runspace. It also adds exception handling and a return value.
Code: Select all
$buttonCallChildForm_Click={
Try{
$ps = [powershell]::Create()
$ps.Runspace = [runspacefactory]::CreateRunspace()
$ps.Runspace.ApartmentState = 'sta'
$ps.Runspace.Open()
$t = Get-Item function:'Show-ChildForm_psf'
$ps.AddScript($t.Definition)
$startPosition = [System.Drawing.Point]::New($this.Parent.Right,$this.Parent.Top)
$ps.AddArgument($MainForm)
$ps.AddArgument($startPosition)
$results = $ps.Invoke()
Write-Host $results[0]
}
Catch{
Throw $_
}
Finally{
$ps.Runspace.Dispose()
$ps.Dispose()
}
}
- daniel kusnir
- Posts: 75
- Last visit: Tue May 23, 2023 10:50 am