tronbabylove
tronbabylove

Reputation: 1102

TableLayoutPanel height for autoscroll based on percentage of visible area

I have an autoscrolling TableLayoutPanel to which I am dynamically adding rows. I would like for the height of each row to be 1/3 of the visible area of the TableLayoutPanel, i.e., the original height of the panel before it gets expanded on the addition of the 4th panel and autoscrolling kicks in. I could just calculate the height for reach row manually and set it as an absolute height, but the TableLayoutPanel could be resized. In that case I could handle the resized event and recalculate the absolute height of each row, but I'm wondering if there is a better way. Is there some way to specify the row height as a percentage of the visible panel area, or should I just go the manual calculation, absolute height route?

Upvotes: 0

Views: 1889

Answers (2)

tronbabylove
tronbabylove

Reputation: 1102

I ended up implementing what I needed in a top-down FlowLayoutPanel, anchored Top, Down, Left, and Right so that it resizes with the form. The first subpanel is added to the FlowLayoutPanel and assigned a width slightly less than the FLP's width. Every subsequent subpanel is given a Dock style of fill, so that its width automatically matches the first panel. Every panel is assigned a height of FLP.Height / 3 and I have a handler for the FLP's resize event to recalculate the height of the subpanels as necessary.

Thanks to everyone who commented and answered. I'm upvoting your answers since they will be helpful to others, just didn't solve my particular issue.

Upvotes: 1

John Arlen
John Arlen

Reputation: 6698

TableLayoutPanel.RowStyle.Percent

Row heights are interpreted as percents of the Table's height

If you have a table with 2 rows, each taking 50% of the panel - and wish to add a 3rd, adjusting all to be 33%:

    tableLayoutPanel1.RowCount = 3;
    this.tableLayoutPanel1.RowStyles[0].Height = 33F;
    this.tableLayoutPanel1.RowStyles[1].Height = 33F;
    this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 33F));

Upvotes: 2

Related Questions