【发布时间】:2017-10-18 02:49:50
【问题描述】:
我不明白为什么这没有在表单中显示新的 PictureBox:
private void Form1_Load(object sender, EventArgs e)
{
generateTable();
}
public void generateTable()
{
//setting up the background tiles
PictureBox setup = new PictureBox();
setup.Width = 100;
setup.Height = 100;
setup.Location = new Point(100,100);
setup.Image = new Bitmap(Application.StartupPath+@"\BlankArea.png");
setup.Visible = true;
this.Controls.Add(setup);
}
它确实找到了图像(用另一个图片框测试)。
【问题讨论】:
-
代码是否可以通过调试器进行单步调试?
-
是的,代码运行得很好,但是图片框没有显示在表单上。
-
很不清楚为什么您不只是与设计器一起添加 PB。在同一位置被另一个控件覆盖是典型的事故。而this mishap 也很常见。
-
尝试:
setup.BringToFront();,设置边框并在调试器中查看控件的属性!
标签: c# picturebox