Page 1 of 1

how to maximise and return a form to windowed state?

Posted: Mon Mar 12, 2018 2:34 pm
by luk4mu5
HI,

I currently have a border-less form and have gone about recreating my own title bar controls.
So far i can drag the window around (that one took me a whole day to figure out), close and minimise. I can maximise to full screen (akin to F11 in a web browser) but cant seems to figure out how to do it with out overlapping the taskbar and then restore it to the previous size once its full screen.

What is the code needed to maximise and restore properly?

Re: how to maximise and return a form to windowed state?

Posted: Mon Mar 12, 2018 3:09 pm
by jvierra
Simplest way:

Code: Select all

    # minimize form
    $winstate = $form1.WindowState
    $form1.WindowState = 'Minimized'
    
    # return to previous state
    $form1.WindowState = $winstate

Re: how to maximise and return a form to windowed state?

Posted: Mon Mar 12, 2018 4:09 pm
by luk4mu5
Perfect thanks! I was getting lost with trying to use derivatives of

Code: Select all

Set-WindowStyle -Style MAXIMIZE -MainWindowHandle (Get-Process -Id $pid).MainWindowHandle
$MainForm.WindowState = 'Minimized'
$MainForm.WindowState = 'Normal'
This worked nicely for the job.

however $MainForm.WindowState = 'Maximized' will still obscure the taskbar. Do you know of a workaround for that?

Re: how to maximise and return a form to windowed state?

Posted: Mon Mar 12, 2018 4:52 pm
by luk4mu5
OK I've got this far

Code: Select all

$buttonMaximize_Click={
$maxlocation = [System.Windows.Forms.SystemInformation]::WorkingArea.Location
$maxsize = [System.Windows.Forms.SystemInformation]::WorkingArea.Size
$form1.Location = $maxlocation
$form1.Size = $maxsize
}
but that will breake

Code: Select all

$form1.WindowState = 'Normal' / $winstate
from returning it to a smaller window.

*edit: and it also wont work on any secondary screen.

Re: how to maximise and return a form to windowed state?

Posted: Mon Mar 12, 2018 5:14 pm
by jvierra
You can have on or the other. If you want a programmable dynamic form then set the size and position. If you want the form to be returned to its' last position and size (minimize) then don't change the form.
You can also save the form sizing object and reset it after a minimize. Look for the event that tells you the form is being activated and reset the saved size.

To manage custom form actions you will need to learn the events of the forms. (size, resize, activated, shown ...) These event allow you to customize this behavior.

As a long time forms programmer - since Windows 0.9 - I can tell you that learning the events and how to use them will allow you to produce highly customized forms. It is a learning curve all programmers have to go through with Windows, Mac, X-Windows(Unix) or any other GUI operating system.

Re: how to maximise and return a form to windowed state?

Posted: Mon Mar 12, 2018 5:39 pm
by jvierra
Here is an old blog post discussing some of the limitations of PowerShell forms.

http://tech-comments.blogspot.com/