Resize DisplayRectangle on TableLayoutPanel row deletion

N

nolan.glore

I am using TableLayoutPanel to dynamically add and remove Controls to
my form. The TableLayoutPanel is set to auto scroll. As Controls are
added the DisplayRectangle height grows but when the Controls are
removed the DisplayRectangle doesn't shrink. This causes extra space
on the bottom of the from. Any suggestions on how to fix this.

Here is the code that sets up the TableLayoutPanel:

m_pnlForm = new TableLayoutPanel();
m_pnlForm.Dock = DockStyl.Fill;
m_pnlForm.AutoScroll = true;
m_pnlForm.Parent = this;

Controls are added by setting it's parent to the TableLayoutPanel

controlToAdd.Parent = m_pnlForm;

Controls are removed by clicking a button that is on the Control to
remove

// here the parent is the TableLayoutPanel
Control parent = controlToRemove.Parent;
parent.Controls.Remove(controlToRemove);

Any help would be much appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top