Resizing and anchoring

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 3 years and 6 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
Lembasts
Posts: 406
Last visit: Mon Apr 15, 2024 3:12 pm
Has voted: 1 time
Been upvoted: 1 time

Resizing and anchoring

Post by Lembasts »

Greetings,
Ive started to anchor stuff but Ive run into another issue. Let's say I wanted to add a button to the bottom of an existing form. Without anchors I could just extend the size of the form and add the button - all other controls would stay where they are.
Now that I have anchors, when I go to extend the form, all the other controls move. It appears I have to manually turn off anchoring for all the controls, extend the form, then turn it back on. Is there a better way?
Thanks
David
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Resizing and anchoring

Post by jvierra »

You have to understand what an anchor does and how to use it. This is just something you need to learn. There is no set of rules. YOu can anchor to any edge or multiple edges.

Here is the description from the docs:

Gets or sets the edges of the container to which a control is bound and determines how a control is resized with its parent.

If you anchor to the bottom or right the control will move with the form edges when resizing. Top,Left will not move.
User avatar
Lembasts
Posts: 406
Last visit: Mon Apr 15, 2024 3:12 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Resizing and anchoring

Post by Lembasts »

I know. But I want to extend the form and add a button to the bottom. Its a real pain to have to undo all the anchors manually to add it then re-add the anchors. I thought there might be an easier way.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Resizing and anchoring

Post by jvierra »

Anchors are not used during design. They are intended to control the dynamic relationships between controls and the forms perimeter. YOU are assuming they are somehow used for designing a form. This will invert the logic of their use and only get you in trouble.

Think about the behavior of controls when the form is being displayed and resized. The anchors set the behaviors for the form when in use.

Anchors are of minimally use in most forms and, when used, require a complete understanding of the design concepts of forms. There are some books that can teach this but all are in VB.Net and C#. The form design rules and techniques are the same but you have to understand how to translate teh code.

The issue you are facing are caused by assuming the PowerShell is an application language. It is not. It is an automation tool and is not designed for or intended to be used to build applications. In PowerShell it is only useful for doing simple things because PowerShell is single threaded and cannot display a main for. All forms are just simple dialogs and these dialogs can only be modal to the caller. Applications require one or more main forms and both modal and modeless dialogs. Trying to extend PowerShell into applications territory is tricky and can only be partly successful and only if the programmer is an advanced Windows programmer. Without the foundations of systems programming the required pieces are very difficult to create in PowerShell.

Rethink anchors and why they exist. They are only good for setting the relationship of a control to the edges. This can be extended to hold fixed relationships between controls anchored to the same place but cannot be used for dynamic positioning of controls. We would use things like the FlowLayoutPanel to create dynamic positioning of controls. We can also use the TableLayoutPanel to create dynamic layouts with the help of code.
User avatar
Lembasts
Posts: 406
Last visit: Mon Apr 15, 2024 3:12 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Resizing and anchoring

Post by Lembasts »

Thanks but I think you are completely misunderstanding my question.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Resizing and anchoring

Post by jvierra »

I can only read your words. YOu have to use less words and make them much clearer. What is it that you are trying to do in one sentence.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Resizing and anchoring

Post by jvierra »

Have you viewed the video that gives instructions on how to work with resizing and anchoring?

https://www.youtube.com/watch?v=Y9FpuKVRdZc
This topic is 3 years and 6 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