TableLayoutPanel - Controls disappeared

jimctr

Well-known member
Joined
Dec 1, 2011
Messages
52
Programming Experience
Beginner
I'm nearing the end of Rev 0 of a project but have stumbled over the form resizing issue. I understand that to resize based upon a screens resolution you should add a TableLayoutPanel. Well, I did so, basically creating a one row-one column table - (best I can do with this design is one row-two column) and moved it to the back. The Charts that I was generating are done so dynamically, and they no longer appear as they had before. I'm not certain how to go about getting the charts and all other controls to reappear.


VB.NET:
 If ChartIsNew = True Then
            Chart1 = New Chart()    'Create a Chart
            Chart2 = New Chart()
            Chart3 = New Chart()
            Chart4 = New Chart()
            Chart5 = New Chart()
            Chart6 = New Chart()
            ChartIsNew = False
            Me.TableLayoutPanel1.SuspendLayout()
            Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
            Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle())
            Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize))
            Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize))
            Me.TableLayoutPanel1.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
            Me.TableLayoutPanel1.AutoSize = True
            Me.TableLayoutPanel1.Dock = DockStyle.Fill
            Me.TableLayoutPanel1.Anchor = AnchorStyles.Left And AnchorStyles.Top
            Me.TableLayoutPanel1.Controls.Add(Me.Chart1, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.Chart2, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.Chart3, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.Chart4, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.Chart5, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.Chart6, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.Calendar1, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.BackButton, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.Label1, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.Panel1, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.MoonPhasePic, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.EnlargeChart, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.HideSer3c, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.HideSer3d, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.HideSer4c, 0, 0)
            Me.TableLayoutPanel1.Controls.Add(Me.HideSer4d, 0, 0)
            Me.TableLayoutPanel1.ColumnCount = 1
            Me.TableLayoutPanel1.RowCount = 1
            Me.TableLayoutPanel1.TabIndex = 1
            Me.Controls.Add(TableLayoutPanel1)
            Me.TableLayoutPanel1.ResumeLayout(False)
            Me.TableLayoutPanel1.PerformLayout()

        End If

And later

VB.NET:
Me.Chart1.Name = "ImageFreqByYear"
                Me.Chart1.TabIndex = 0
                Me.Chart1.Text = "Image Frequency Per Year"
                Me.Chart1.BringToFront()
                Me.Chart1.Anchor = AnchorStyles.Left And AnchorStyles.Top
                Me.Chart1.Dock = DockStyle.None
                Me.Controls.AddRange(New System.Windows.Forms.Control()  {Me.Chart1})     ' Add chart control to the form



TableLayoutPanel1 properties: Anchor: Top,Left; AutoSize:True; AutoSizeMode: GrowAndShrink; ColumnCount: 1; RowCount: 1; Dock: Fill
 
Last edited:
OK. After closing My MS Studio and Reopening the objects are appearing but the rendering is all screwed up now. This is where things should be placed relatively:
NormalPlacement.JPG

This is where they are ending up. Why is this happening?
Abnormal1.JPG
 

Attachments

  • Abnormal2.JPG
    Abnormal2.JPG
    243.6 KB · Views: 41
I understand that to resize based upon a screens resolution you should add a TableLayoutPanel.
That is certainly not true, or at least not true in all cases. A TableLayoutPanel is useful when resizing if you want to keep controls to predefined proportions when resizing, but it's certainly not required in all cases and a TLP with its Anchor set to Top, Left is pretty much useless when it comes to resizing. Take a look at this for how to use a TLP to maintain proportions of its child controls and also how it can interact with sibling controls:

Anchor & Dock For Automatic Resizing
 
Also realize one cell in TableLayoutPanel can only parent one child control (which itself can be a container). I see several places in your code that you attempt to add multiple controls to same cell, what happens then is that controls are pushed to other cells and table is expanded as needed (GrowStyle) to parent the additional controls.
 
Here is the quandry I have. I am generating a series of drill down charts, 4 levels in all, and depending upon the Level, will occur in different parts of the screen and in different proportions. For the first two levels, the charts will be roughly in the center of the screen and the second level chart will be larger than the first. In the 3rd and 4th level, the charts will take up about 2/3rd of the screen, one located left top and other other located left bottom(as you can see from the depictions above). On the 3rd level, the top graph will be able to be dynamically expanded to take up top and bottom, while the bottom graph is made invisible. This is all taking place on a single form. Is there a way to dynamically merge and split cells? What do I do in the case of the picture box sitting on a panel if only one cell in TableLayoutPanel can parent only one control (well, maybe a panel is not considered a control)? What do I do in the case where a series of check boxes overlap a graph? Does the FlowLayoutPanel suffer from the same constraints as the TableLayoutPanel?

I'm just curious. Labview, the graphical user interface supported by graphical objects, allows you to set a project property to automatically re-proportion itself based on screen resolution and they do so without having to implement constructs such as TableLayoutPanel or FlowLayoutPanel. I'm just curious why VB can't do the same. This seems to make things more complex than they need to be.

Is there any way to do this successfully without having to resort to TableLayoutPanel or FlowLayoutPanel? Basically, when I port this design to a smaller screen, the design runs off the side of the screen
 
Last edited:
A Panel is a control. Each cell can parent only one control but that control can parent as many other controls as you like. If you want multiple controls in one cell then put those multiple controls on a Panel and then put the Panel in the cell. The Panel is the only control parented by the cell so there's no issue. Only the most complicated of layouts can not be handled with proper use of one or more TableLayoutPanels and/or one or more FlowLayoutPanels.
 
Fixed layouts are so annoying.... You can do any perfectly resizable layout you want by using the tools available with any control: Docking and Anchoring.
 
Back
Top