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

时间:2016-01-24 20:44:06

标签: c# image picturebox spaces tablelayoutpanel

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

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);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

也许你的照片有边距。试试这个:

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