Is there a method to reassign anchor after control move?

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 8 years and 4 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
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Is there a method to reassign anchor after control move?

Post by dan.potter »

I have a textbox on the left side of my form that I expand and collapse(show/hide). When I hide it I shift a panel with the remaining controls to the left and resize it. Is there a way to reapply the anchor instead of resizing?


Here is what I'm currently doing which works fine, just wondering if there's an easier way.
  1. if ($serverlistbox.Visible) {
  2.        
  3.         $serverlistbox.hide()
  4.         $panel1.Location = "16, 4"
  5.        
  6.         $currhght = $panel1.Size.Height
  7.         $newwidth = $panel1.Size.Width + 224
  8.        
  9.         $panel1.Size = "$newwidth,$currhght"
  10.        
  11.         $expand.Text = ">"
  12.        
  13.     } else {
  14.        
  15.         $panel1.Location = "240, 4"
  16.         $serverlistbox.show()
  17.        
  18.         $currhght = $panel1.Size.Height
  19.         $newwidth = $panel1.Size.Width - 224
  20.        
  21.         $panel1.Size = "$newwidth,$currhght"
  22.        
  23.         $expand.Text = "<"
  24.        
  25.     }
Untitled.png
Untitled.png (20.28 KiB) Viewed 2260 times
Untitled2.png
Untitled2.png (16.71 KiB) Viewed 2260 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Is there a method to reassign anchor after control move?

Post by jvierra »

Use a splitter and move the splitter bar. Set controls on half panel docked-full.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Is there a method to reassign anchor after control move?

Post by dan.potter »

Thanks, will play. Happy Thanksgiving.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Is there a method to reassign anchor after control move?

Post by dan.potter »

:( I must be missing something. I can't move it.

Splitter control must be docked left, right, top, or bottom.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Is there a method to reassign anchor after control move?

Post by jvierra »

dan.potter wrote::( I must be missing something. I can't move it.

Splitter control must be docked left, right, top, or bottom.
Dock splitter in form. Place controls to hide on one side. Place other controls on other side and set to anchor/dock as needed. Tey should follow the splitter was it is opened collapsed.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Is there a method to reassign anchor after control move?

Post by dan.potter »

split container correct?
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Is there a method to reassign anchor after control move?

Post by dan.potter »

got it, thanks for the help.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Is there a method to reassign anchor after control move?

Post by jvierra »

It won't work for all designs but it is the closest thing I can think of to what you are asking.
This topic is 8 years and 4 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