I know I can set the childform to open on CenterParent. However, during my script if a variable is true, I need to resize the already open ChildForm it to accommodate the new objects on the screen.
How would I reset the child location to the center of parent after resizing?
Relocate child form after opening and resizing
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.
-
- Posts: 24
- Last visit: Mon Feb 06, 2023 11:30 am
- Has voted: 1 time
Re: Relocate child form after opening and resizing
Reset to upper right location to the computed offset center of the screen.
This is best done in the resizing. You can resize and reposition in one line of code not including the arithmetic.
This is best done in the resizing. You can resize and reposition in one line of code not including the arithmetic.
Re: Relocate child form after opening and resizing
Simple example:
- $xpos = 100 # computed new X position
- $ypos = 100 # computed new Y position
- # the following moves the form to the new location
- $form1.Location = [System.Drawing.point]::new($xpos, $ypos)
-
- Posts: 24
- Last visit: Mon Feb 06, 2023 11:30 am
- Has voted: 1 time
Re: Relocate child form after opening and resizing
Yes Sure, that does it...
but what happens when my main form is not in it's original place? I expect those coordinates to be way off..
I have seen some post regarding carrying an object variable ( $label ) during the show-childform execution but I don't understand what's happening
cheers.
but what happens when my main form is not in it's original place? I expect those coordinates to be way off..
I have seen some post regarding carrying an object variable ( $label ) during the show-childform execution but I don't understand what's happening
cheers.
- $p = $label.Parent.PointToScreen($label.Location)
- $p.X -= ($formChildForm.Size.Width/2) - ($label.Size.Width/2)
- $p.Y -= $formChildForm.Size.Height
- $formChildForm.Location = $p
-
- Posts: 24
- Last visit: Mon Feb 06, 2023 11:30 am
- Has voted: 1 time
Re: Relocate child form after opening and resizing
I have read many of your posts so I know when you say something you are sure of it.. One line worked for me once I started simple and used the debugger.
#Move the form after resize
$p = $Bannerlabel.Parent.PointToScreen($Bannerlabel.location)
$childform.Location = "$($p.x+110),$($p.y+30)"
Tested this method on my 4k and native laptop 1080p
Re: Relocate child form after opening and resizing
As I noted above, you have to do the arithmetic and use the current values for the screen and the form. Remember arithmetic? It was that class you slept through in elementary school. Time to remember how to add, subtract, multiply and divide.
Get the width and height of bot screen and form and computer the new X and Y locations.
Get the width and height of bot screen and form and computer the new X and Y locations.
-
- Posts: 24
- Last visit: Mon Feb 06, 2023 11:30 am
- Has voted: 1 time
Re: Relocate child form after opening and resizing
Why are you being rude? You know nothing about me.
Did you even read the part where I solved my own problem or did you just sleep through that? What about the part where I said I've read your posts and tried to show appreciation.
Did you even read the part where I solved my own problem or did you just sleep through that? What about the part where I said I've read your posts and tried to show appreciation.
Re: Relocate child form after opening and resizing
If it works, then use it although it won't work on every screen aspect ratio which is why you have to use constants.
There are more ways to do things poorly and only a very few ways to do things correctly. Poor methods eventually fail.
If you are satisfied, then OK.
There are more ways to do things poorly and only a very few ways to do things correctly. Poor methods eventually fail.
If you are satisfied, then OK.
-
- Posts: 24
- Last visit: Mon Feb 06, 2023 11:30 am
- Has voted: 1 time
Re: Relocate child form after opening and resizing
You'll need more than a bunch of words to prove your point to me to say that I'll fail when you're just assuming. I know when I point fingers there are three pointing back.
Please be kind and be helpful or sit in the corner.
Please be kind and be helpful or sit in the corner.
Re: Relocate child form after opening and resizing
Not assuming. I have been building Windows applications for almost four decades.
Don't worry. If you are happy then you may eventually learn when things fail. For the two test you made you are OK. If it fails on the third different screen, then consider using arithmetic and screen/form sizes to set the location to relative center.
Don't worry. If you are happy then you may eventually learn when things fail. For the two test you made you are OK. If it fails on the third different screen, then consider using arithmetic and screen/form sizes to set the location to relative center.