【问题标题】:How to fix the size of my TableLayoutPanel-pictures?如何修复我的 TableLayoutPanel 图片的大小?
【发布时间】:2016-05-01 02:11:26
【问题描述】:

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

【问题讨论】:

  • 在这里使用SizeMode = AutoSize 完全没有意义。
  • 我删除了它,但我没有改变任何东西......

标签: c# image picturebox spaces tablelayoutpanel


【解决方案1】:

也许您的图片有边距。试试这个:

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

【讨论】:

    猜你喜欢
    • 2015-04-23
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多