0

I managed to create an array of Picture Boxes.

private: static array<System::Windows::Forms::PictureBox^>^ pictures = (gcnew array<System::Windows::Forms::PictureBox^>(64));

Now, I would like to spawn a Picture Box if a certain position (coordX,coordY) is free. Is there a way to do this?

Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122
KamiV
  • 109
  • 4

1 Answers1

0

you need a rectangle intersect algorithm then you do sometings like this

var desiredX = ?;
var desiredY = ?;
var desiredW = ?;
var desiredH = ?;
var intersect = false;

foreach(var picture in pictures){
   if(picture intersect(desiredX, desiredY, desiredW, desiredH)){
     intersect = true;
     break;
   }
}

if(!intersect){
  //add new picture here
  pictures.add(newPicture);
}

For intersect algoritm you can look here

Mustafa Çetin
  • 311
  • 2
  • 10
  • I suppose I can convert the Foreach loop into a C++ For loop. – KamiV Mar 11 '18 at 21:40
  • @KamiV You can use the C++/CLI [`for each`](https://msdn.microsoft.com/en-us/library/ms177202.aspx). It's one of the [spaced keywords](https://blogs.msdn.microsoft.com/hsutter/2003/11/23/ccli-keywords-under-the-hood/). – Tom Blodget Mar 13 '18 at 03:18