Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VS2005 Windows App Anchoring 1

Status
Not open for further replies.

NervousRex

Programmer
Sep 4, 2003
66
US
Sorry if this is wrong forum to post this...

Easiest way to explain this is: I am trying to replicate an HTML table design of 2 columns with 50% widths. Meaning that as the page size is increased, both columns grow equally.

I'm trying to do this on a windows form...with two group boxes. As the page is resized, I would like them to grow equally so that they remain in same relative positions. Is there an easy built in way to do this, or do I need to set the sizes and position through code when the form is resized?

|[<--->] [<--->]|


 
1. Add a "TableLayoutPanel" control to your form. These are in the Toolbox under the Containers tab.

2. Size the TableLayoutPanel so that it takes up the width of the form.

3. Set the Anchor of the TableLayoutPanel to Left, and Right, and either Top or Bottom (or neither of these), depending on your layout.

4. Make sure your TableLayoutPanel has one row and two columns.

5. By default, your TableLayoutPanel should have each column as 50% of the width, but you can change this in the properties if not.

6. Add each GroupBox to a cell in the TableLayoutPanel, and set the Dock to Fill on the GroupBoxes.
 
Have another issue that is layout related, so figure I'll update here instead of a new post...

I had the above working...but then I needed to add some more functionality. So what I have now is three group boxes within a flowlayout panel. When I close/hide the top group box, the bottom 2 move up the form as I want them too. The issue now is that the group boxes no longer stretch across the form like they did before being placed on the flowlayout panel. They always remain the same width even though I have them anchored. I also have the flowlayout panel docked to fill.



 
I'm having trouble picturing your layout. However, if I am thinking correctly, and your layout will support this behavior, try docking the FlowLayoutPanel to the left of your form (or the container it's in).
 
The layout hierarchy is:

Form
FlowLayout
-GroupBox(1) - with expand/collapse feature
+GroupBox(2) - with expand/collapse feature
TableLayout (2 columns w/ 50% width)
GroupBox(a) | GroupBox(b)
+GroupBox(3) - with expand/collapse feature
TableLayout (2 columns w/ 50% width)
GroupBox(a) | GroupBox(b)


Basically (1,2,3) are not stretching the width of the form, which prevents (a,b) from doing what you answered for me yesterday.


If I remove the FlowLayout panel and change nothing else, they stretch across the form correctly, but I lose the functionality of when (1) is closed(+/-), (2) and (3) should move up to the top of the form.
 
I believe I can achieve the same functionality I am looking for by using the TableLayout instead of the FlowLayout by setting the row height to autosize.

So far it looks good.


I searched google, and it appears my problem is a common gripe with the FlowLayout panel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top