Adding a Textbox to Existing GUI and relocating other objects

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 5 years and 8 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
Jamitch
Posts: 2
Last visit: Wed Aug 01, 2018 1:05 pm

Adding a Textbox to Existing GUI and relocating other objects

Post by Jamitch »

I'm having trouble finding a way to add a textbox (or frankly any new object in general) to a specific location in an existing GUI whilst relocating other objects. I have created a button that allows me to add a new textbox and I have been using this command line to set its location:

$textBox.Location = New-Object System.Drawing.Point($x, $y)

It has worked so far, but my only problem is that I have other objects (labels, buttons, textboxes, etc.) blocking the location of where I want to create the new textbox. So rather than resetting the location of every object manually with the command line above and adding the box, I was wondering if there was a way to move everything simultaneously with one or two lines of code. More specifically, if there was a way to move all objects below a certain object in a GUI easily.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding a Textbox to Existing GUI and relocating other objects

Post by jvierra »

You can use a FlowLayoutPanel which can automatically position controls.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Adding a Textbox to Existing GUI and relocating other objects

Post by localpct »

Are there any examples of these? I’ve never been able to wrap my head around these
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding a Textbox to Existing GUI and relocating other objects

Post by jvierra »

If you search you will find many examples.
There is one example in the sub-form in the following blog article.

http://tech-comments.blogspot.com/2017/ ... forms.html

Download and run the sample code. Look at the code for the sub-form to see how it dynamically builds a form with a variable number of textboxes and labels. It may appear complicated but, once you understand how it works you will be able to use the techniques in many places and ways.
User avatar
Jamitch
Posts: 2
Last visit: Wed Aug 01, 2018 1:05 pm

Re: Adding a Textbox to Existing GUI and relocating other objects

Post by Jamitch »

Thank you for the information! There is also a great YouTube video that gives you the basics if you are new to the FlowLayoutPanel tool.

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