我试图使用以下代码绘制大量图像实例:
PictureBox[] sprites = new PictureBox[100];
private void Game_Load(object sender, EventArgs e)
{
PictureBox mainSprite = new PictureBox();
Bitmap img = new Bitmap(SpriteTest.Properties.Resources.Image); //Load a png image
mainSprite.Size = new Size(16, 16);
mainSprite.Image = img;
for(var i = 0; i < sprites.Length; i++)
{
sprites[i] = mainSprite;
//Keeping it simple for now with a single row of sprites
sprites[i].Location = new Point(i * 16, 8);
}
Game.ActiveForm.Controls.AddRange(sprites);
}
Run Code Online (Sandbox Code Playgroud)
在运行代码时,只显示最后一张图像.在调试代码时,一切似乎都按预期工作.我还可以验证该位置实际上是否正在更新.
我还尝试使用for循环中的以下代码以不同的方式添加控件(没有运气);
this.Controls.Add(sprites[i]);
Run Code Online (Sandbox Code Playgroud)
我多次遇到过这个问题,特别是当我尝试以类似的方式创建许多GroupBox时.在我试图寻找解决方案时,我在网上搜索了几个小时,没有任何修复过.
我试图将数据放入二维数组但是得到错误它将值添加到0,0位置然后是1.0位置等等,请使其正确
int count = output.Tables[0].Rows.Count;
string[,] terms = new string[count,2];
for (int runs = 0; runs < count; runs++)
{
terms[0,runs] =output.Tables[0].Rows[runs][0].ToString();
terms[0,runs] =output.Tables[0].Rows[runs][2].ToString();
}
Run Code Online (Sandbox Code Playgroud)
希望对你有所帮助..