我正在为一个学校项目创建一个小型WindowsForm Dice Game,其中一个规范是用障碍物的文本文件读取它们的位置以及可以移回的空间。我已成功将包含此信息的文本文件读入锯齿状数组,现在我需要生成PictureBox来充当障碍物。代码编译良好,一切似乎工作,但PictureBoxes没有显示在我的形式。 x和y值是正确的,并在表单内。 if语句正在检查障碍物是向前还是向后发送玩家并相应地更改图像。在运行时添加PictureBoxes
int obstacleX = Convert.ToInt32(lbl.Location.X) - 14;
int obstacleY = Convert.ToInt32(lbl.Location.Y) + 6;
PictureBox obstacle = new PictureBox();
if (Library.GlobalVariables.obstacleStats[i][1] < 0)
{
obstacle.Image = Properties.Resources.badObstacle;
}
else
{
obstacle.Image = Properties.Resources.goodObstacle;
}
obstacle.Location = new Point(obstacleX, obstacleY);
obstacle.Size = new Size(17, 17);
obstacle.Show();
this.Controls.Add(obstacle);
有什么明显的我失踪了吗?
感谢您的帮助,
乔希
你应该重绘屏幕以显示新的对象。 – nocturns2
如何重画屏幕? this.Refresh()似乎没有任何作用。 –
如果pbox与另一个控件重叠,则追加obstacle.BringToFront()。 –