List<Control> lstPicBoxes = new List<Control>();
lstPicBoxes.Add(PictureBox1);
// add other pictureboxes to list ...
//private void label1_KeyDown(object sender, KeyEventArgs e)
// or
private void Form1_KeyDown(object sender, KeyEventArgs e)
{ switch (e.KeyCode) { case Keys.Up: label1.Location = new Point(label1.Location.X, label1.Location.Y - 1); break; case Keys.Down: label1.Location = new Point(label1.Location.X, label1.Location.Y + 1); break; case Keys.Right: label1.Location = new Point(label1.Location.X + 1, label1.Location.Y); break; case Keys.Left: label1.Location = new Point(label1.Location.X - 1, label1.Location.Y); break; } // for(int i = 0;i< lstPicBoxes.Count; i++) { if (label1.Bounds.IntersectsWith(lstPicBoxes[i].Bounds)) { lstPicBoxes[i].Visible=false; // or dispose picturebox : //this.Controls.Remove(lstPicBoxes[i]); // remove from the form //lstPicBoxes[i].Dispose(); // dispose //lstPicBoxes.RemoveAt(i); } }
}
+ نوشته شده در دوشنبه 18 اسفند 1399 ساعت: 6:26 توسط محمد رضا جوادیان
برچسب ها:
|