-2

I'm building a drag/drop application in winforms c#, i need to drag a usercontrol and drop it to a flowlayoutpanle. everything works fine, except the drop location, the flowpanel sets the droped items side by side. how can I set the droped item to the the exact cursor position?

Luke
  • 751
  • 2
  • 7
  • 32
Arh Hokagi
  • 170
  • 5
  • 21

1 Answers1

1

I'll extend my comment to an answer.

The problem is not based on drag'n'drop. The problem is based on a semantic level. A flowlayoutpanel is used, to automatically arrange it's contents.

See MSDN FlowLayoutPanel Control Overview

The FlowLayoutPanel control arranges its contents in a horizontal or vertical flow direction. You can wrap the control's contents from one row to the next, or from one column to the next. Alternately, you can clip instead of wrap its contents.

So the flowlayoutpanel-control does exactly what it's supposed to do. If you want to give the dropped control a specific location based on coordinates you want to use a normal panel. A normal panel will not arrange its contents automatically.

Luke
  • 751
  • 2
  • 7
  • 32
  • Doesn't even require a `Panel`, the `Form` itself can be used – boop_the_snoot Jul 25 '17 at 11:52
  • @Nobody I think the FormClass itself already contains a main Panel for all its controls. Using an extra Panel for your controls can help you to organize your form. But you are right, using the panel is optional. – Luke Jul 25 '17 at 11:54
  • Thanks Luke, yes i switched to the Panel control, and used the `myusercontrol.Location = panel1DropZone.PointToClient(x,y)` to get the coordinate, but this time the droped item is not accuratly droped where the mouse is. have you any idea why? – Arh Hokagi Jul 25 '17 at 12:19
  • The `.Location` property gets or sets the top left corner position of your control. Since you use Drag'n'Drop you will probably have your mouse somewhere in the middle of the control. Your application will have to do some maths to calculate the actual top corner coordinates using the mouse position in relation to the draged object. – Luke Jul 25 '17 at 12:37