C# – Change row/column span programmatically (tablelayoutpanel)

ctablelayoutpanelwinforms

I have a tablelayoutpanel. 2×2 – 2 columns 2 rows.

For example, I added a button button1 in a 1 row, second column. button1 has a dock property set to Fill. VS Designer allows to set column/row span properties of button1.

I want an availability to change row span property of button1 programatically, so it can fill all second column(1 row and second row) and availability to set it back.

How?

Best Answer

What about this code?

private void button1_Click(object sender, EventArgs e)
{
    var control = sender as Control;

    if(control == null)
        return;

    if (1 == tableLayoutPanel1.GetRowSpan(control))
    {
        tableLayoutPanel1.SetRowSpan(control, 2);
    }
    else
    {
        tableLayoutPanel1.SetRowSpan(control, 1);
    }
}
Related Topic