0

I've just found a similiar question to this here:

C# Drag and Drop with one pictureBox

It just works fine for me, what the first answer contains, but my problem is, that I want to make a Winforms App where it is possible to drag and drop more than one pictureBox elements on another. I mean in the example it's just possible to drag and drop a single pictureBox on another. But I want to drag and drop more pictureBoxes on the largest one.

To better understand what I'm up to: I want to program a classic game with C#:

Battleship (game)

By the way: I have already advanced skills in programming with C# but I never made a Winforms application with Drag and Drop events.

Thanks for your help!

Community
  • 1
  • 1
  • well what happens if you try to drag another picturebox onto it? – CularBytes Dec 21 '14 at 17:59
  • It's not really your question, but why don't you do it in a different way: just have sort of `BlockStates`. Just change the image when a ship is hit. You'll have to do some calculating with the edges and stuff, but you get the idea right? – CularBytes Dec 21 '14 at 18:04
  • If you're looking to place more than one image on a larger picturebox (like in a grid formation) then you'll need to change the design up a bit. Are you perhaps trying to figure out how to allow the user to drag/drop the different sized ships onto the playing field for initial placement? One possibility would be to use a Panel as the field, and then have each ship in its own PictureBox that gets placed by the user. As they are moved around you can make them "snap" to the grid by doing some calculations. – Idle_Mind Dec 21 '14 at 18:47
  • One picturebox contains one image. (Discounting the background image and the surface). So your approach must either change to something grid-like by design, like a datagridview or you will have to a) detect the spot you drop on and then b) paint the droppped graphic into that space in the pb's image thereby changing its pixels. The first is simpler and easier to revert imo, but both are doable of course.. – TaW Dec 21 '14 at 18:59
  • 1
    BTW: I wonder if D&D is such a good technique: It will usually show you a D&D __icon__ without indicating which part of the ship you have started the drag on and how it is directed. But this information is necessary for placing it correctly. I think I would code my own D&D by actually moving a PB or something that looks like the ship and let the user place it with full visual control. (But maybe I don't do enough D&D and there is a better way to preview what is being dragged..) – TaW Dec 21 '14 at 19:06
  • You could update the board in real time within the DragOver() event to show where the piece will be placed. – Idle_Mind Dec 21 '14 at 19:56

0 Answers0