There's some spacing between the Buttons I add to my TableLayoutPanel
. I removed the border in the Button and set the Margin and Padding to 0 in the Panel. But I continue getting that spacing.
tableLayoutPanel.RowCount is set to 8 and the Rows
collection I've added 8 rows with Size Type Absolute
.
Am I missing something? Here's the code:
private void FillSelectLayout()
{
tableLayoutPanelSelect.Controls.Clear();
tableLayoutPanelSelect.RowStyles.Clear();
tableLayoutPanelSelect.RowCount = 8;
for (int i = 0; i < 8; i++)
{
Button buttonSelector = new Button();
buttonSelector.Height = 64;
buttonSelector.Width = 100;
buttonSelector.FlatStyle = FlatStyle.Flat;
buttonSelector.FlatAppearance.BorderSize = 0;
buttonSelector.BackColor = Color.Yellow;
tableLayoutPanelSelect.Controls.Add(buttonSelector, 0, i);
}
}
Here's how it's displayed:
To remove the space between buttons in cells, it's enough to set dock property of them to fill and then remove default margins of buttons:
Note:
Usually it's better to set
Dock
property of controls which you host in cells toFill
. This way your controls will followTableLayouPanel
sizing rules which you set for columns and rows.TableLayoutPanel
useMarging
property of control to set the location of control in cell. So If you don'n want to setDock
and you prefer to set theSize
manually, it's enough to set theMargin
only.I .. set the Margin and Padding to 0 in the Panel.
Why didn't you remove the
Margin
in theButtons
instead:MSDN:
I faced the same problem while using different control in
TableLayoutPanel
You can do this
Show:
selectRows
and again select Autosize.