views:

655

answers:

1

I am using a TableLayoutPanel to split a client area into 3 rows. (There is only 1 column)The top and bottom rows are designed to be of fixed height; they will contain a header and a footer which initially each contain a child lable control that contain static text (just to start off with). The midde row should be dynamically sized to fill remaining area. This middle pane will eventually contain a listview. I have a manager class that takes as an argument the panel (ExplorerTableLayoutPanel) object being managed:

public class ExplorerTableLayoutPanelManager
{       
    public ExplorerTableLayoutPanelManager(ExplorerTableLayoutPanel panel)
    {
        LayoutPanel = panel;
    }

There are 3 methods that create each of the 3 rows in the table layout:

    private void AddHeaderRow()
    {
        const int headerHeight = 30;
        LayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, headerHeight));

        Label label = new Label();
        label.BackColor = Color.AliceBlue;
        label.BorderStyle = BorderStyle.None;
        label.ForeColor = Color.LightGray;
        label.TextAlign = ContentAlignment.MiddleRight;
        label.Text = "Header Banner";
        label.Dock = DockStyle.Fill;
        float size = label.Font.SizeInPoints;
        label.Font = new Font(label.Font.Name, size * 2);

        const int column = 0, row = 0;
        LayoutPanel.Controls.Add(label, column, row);
    }


    private void AddBodyRow()
    {
        LayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));

        Label label = new Label();
        label.BorderStyle = BorderStyle.FixedSingle;
        label.ForeColor = Color.LightGray;
        label.TextAlign = ContentAlignment.MiddleCenter;
        label.Text = "Content Under construction ...";
        label.Dock = DockStyle.Fill;

        float size = label.Font.SizeInPoints;
        label.Font = new Font(label.Font.Name, size * 2);

        const int column = 0, row = 1;
        LayoutPanel.Controls.Add(label, column, row);
    }


    private void AddFooterRoow()
    {
        const int footerHeight = 30;
        LayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, footerHeight));

        Label label = new Label();
        label.BackColor = Color.AliceBlue;
        label.BorderStyle = BorderStyle.None;
        label.ForeColor = Color.LightGray;
        label.TextAlign = ContentAlignment.MiddleRight;
        label.Text = "Footer Banner";
        label.Dock = DockStyle.Fill;

        float size = label.Font.SizeInPoints;
        label.Font = new Font(label.Font.Name, size * 2);

        const int column = 0, row = 2;
        LayoutPanel.Controls.Add(label, column, row);
    }

The problem I am seeing is that the last row is taking up the fixed row hieght which i have requested as 30. This part is correct. However, the first and second rows are spliting the remaining space equally between them which is not what I want. As you can see, I have explicitly set the row height to 30 for the first row in exactly the same manner as done for the last row, but this deoesn't appear to work. The 2nd row (middle) has its RowStyle size set to SizeType.AutoSize which I though was meant to mean use up the remaining space, so don't explicitly set the size. I may be wrong but I'm not sure.

Any help would be most appreciated,

regards.

+1  A: 

I haven't tested your code but at a glance:

private void AddBodyRow()    
{
    LayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
    ...

Since you want to fill the remaining space don't want SizeType.AutoSize otherwise the body row will try to shrink to fit the label, even though the label is set to DockStyle.Fill. What you want is to make the row fill up all the space it can by using SizeType.Percent:

private void AddBodyRow()    
{
    LayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100f));
    ...
Stuart
Thanks for your response. I have learnt the error of my ways with regards to this particular issue and now realise that 100% means fill up all the remaining space after the rows with absolute style have been allocated. Thanks again.
Shantaram