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?
how to maximise and return a form to windowed state?
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: how to maximise and return a form to windowed state?
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?
Perfect thanks! I was getting lost with trying to use derivatives of
$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?
- Set-WindowStyle -Style MAXIMIZE -MainWindowHandle (Get-Process -Id $pid).MainWindowHandle
$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?
OK I've got this far
but that will breake from returning it to a smaller window.
*edit: and it also wont work on any secondary screen.
- $buttonMaximize_Click={
- $maxlocation = [System.Windows.Forms.SystemInformation]::WorkingArea.Location
- $maxsize = [System.Windows.Forms.SystemInformation]::WorkingArea.Size
- $form1.Location = $maxlocation
- $form1.Size = $maxsize
- }
Code: Select all
$form1.WindowState = 'Normal' / $winstate
*edit: and it also wont work on any secondary screen.
Re: how to maximise and return a form to windowed state?
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.
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?
Here is an old blog post discussing some of the limitations of PowerShell forms.
http://tech-comments.blogspot.com/
http://tech-comments.blogspot.com/