Problem in removing the controls dynamically
<p>Note : In WinForm</p>

<p>I facing problem in TableLayoutPanel. I adding and removing the control dynamicall using TableLauoutPanel. My problem is, if i remove the control in the middle (ie i added TextBox1, TextBox2 and TextBox3 and now i removed TextBox2) at this time other controls are not resized properlly. When the last control (ie TextBox3 ) is removed, its resizing properlly. I attached my code here. What is the problem?</p>

<p>///HERE tbl is the TableLayoutPanel</p>

<pre><code>private void AddText_Click(object sender, EventArgs e)
{    
    TextBox txt = new TextBox();
    txt.MouseDoubleClick += new MouseEventHandler(txt_MouseDoubleClick);
    txt.Multiline = true;
    txt.Dock = DockStyle.Fill; NEWADD(txt);
}

private void NEWADD(Control ctrl)
{
    tbl.RowCount += 1;
    tbl.RowStyles.Add(new RowStyle(SizeType.Percent, 100F / tbl.RowStyles.Count));
    tbl.Controls.Add(ctrl, 0, tbl.RowStyles.Count - 1); 

    foreach (RowStyle row in tbl.RowStyles)
    {
     row.SizeType = SizeType.Percent;
     row.Height = 100F / (tbl.RowStyles.Count);
    }
}

private void RemoveControl(Control ctrl)
{ 
    tbl.RowCount -= 1; 
    tbl.Controls.Remove(ctrl); 
    tbl.RowStyles.Clear();

    for (int i = 0; i &lt; tbl.Controls.Count; i++)
    {
     tbl.RowStyles.Add(new RowStyle(SizeType.Percent, 100F /( tbl.RowStyles.Count +1)));
    }

    foreach (RowStyle row in tbl.RowStyles)
    {
     row.SizeType = SizeType.Percent;
     row.Height = 100F / (tbl.RowStyles.Count);
    }

    tbl.Refresh();
} 

void txt_MouseDoubleClick(object sender, MouseEventArgs e)
{
    RemoveControl(sender as Control);
}
</code></pre>
