0

In my code I have some pictureboxes that are clicked onto a panel by the user. Wherever the user clicks a picture box is placed. The location is stored in a database so that it can be called back later.

When a user clicks a picturebox it changes the backcolor property to red to give the impression of it being highlighted.

My issue is I want to add a groupbox (or another method of surrounding) around the highlighted boxes. So a user clicks say 4 picture boxes and clicks "Surround" button and it draws a groupbox around those 4 pb's. But I am at a loss since I don't know how to get the location of the outer pictureboxes (the ones that the group needs to surround) since they are all done on the fly?

Any advice would be great.

User9123
  • 23
  • 5
  • 1
    What if there are multiple pictureboxes in this area where some are selected and others not? Do you want to move the unselected boxes outside of the group-area? – Tim Schmelter May 11 '16 at 15:06
  • Hi Tim, Its unlikely that would be the case, imagine a restaurant application where you would align a set of tables then assign those tables to a section. You wouldn't have a table from one section in the middle of another – User9123 May 11 '16 at 15:15

1 Answers1

1

You probably have the list of all pictureboxes in your application somewhere (if you place them inside a container, that would be Children property). I suggest you simple foreach through all picture boxes and find min/max coordinates, and from there you can easily get the coordinates for the surrounding box. You might be able to do all that using one LINQ query.