我正在寻找答案,但找不到任何东西,所以:
我正在制作简单的项目,但对此有疑问:
// fragment of code in parent form
Random r = new Random();
private void BeginGame()
{
SetName();
sheep = new Sheep[howManySheep];
for (int i = 0; i < howManySheep; i++)
sheep[i] = new Sheep(this);
(...)
}
public Sheep DrawSheep
{
set
{
splitContainer1.Panel2.Controls.Add(value);
}
}
// fragment of code in child form
class Sheep : Button
public Sheep(Form1 _parent)
: base()
{
var p = new Point(r.Next(_parent.PanelSize[0]), r.Next(_parent.PanelSize[1]));
Text = null;
Size = new Size(size, size);
BackColor = Color.White;
Tag = nrSheep++;
Location = p;
_parent.DrawSheep = this;
MessageBox.Show(this.Location.ToString());
}
当 MessageBox.Show(..) 被注释时,它只画了一只羊(我的意思是所有的羊,但在同一个地方) 当 MessageBox.Show(..) 没有注释时,它画的一切都很好,它应该是怎样的。我的问题是如何?