如何修复我的 TableLayoutPanel 图片的大小?

How to fix the size of my TableLayoutPanel-pictures?

我的 TableLayoutPanel 有问题。 每个单元格都包含一个图片框,但是当我想显示我的 TableLayoutPanel(带有图片)时,图片之间出现一些 "spaces"...我该如何解决它?

Please have a look at this to see my problem

这是我的代码:

private void button1_Click(object sender, EventArgs e)
{
    _hauteurMap = Convert.ToInt32(numericUpDown1.Value);
    _largeurMap = Convert.ToInt32(numericUpDown2.Value);

    tableLayoutPanel1.ColumnCount = _largeurMap;
    tableLayoutPanel1.RowCount = _hauteurMap;

    tableLayoutPanel1.Controls.Clear();

    int i, j;

    for (i = 0; i < _hauteurMap; i++)
    {
        for (j = 0; j < _largeurMap; j++)
        {
            PictureBox pb = new PictureBox
            {
                Size = new Size(20, 20),
                SizeMode = PictureBoxSizeMode.AutoSize
            };

            pb.Image = Image.FromFile("C:/Users/Sébastien/Documents/Visual Studio 2010/Projects/IsometricTileEngine_ITE/IsometricTileEngine_ITE/bin/Images/empty_tile.png");
            tableLayoutPanel1.Controls.Add(pb, j, i);
        }
    }
}

可能你的图片有边距。试试这个:

PictureBox pb = new PictureBox
{
    Size = new Size(20, 20),
    Margin = new Padding(0)
};