Move controls when Drag and drop on panel in C#

后端 未结 2 1253
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 13:37

I want to drag controls on panel and when dragging I want to move the control and get its location to drop on to panel. I have tried out mouseUp, mouseDown, MouseMove events

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 14:25

    If your control is already on the panel and you're simply moving it within the same panel, then using the Mouse events is probably the easiest way to do this. My understanding is that Drag and Drop is more about conveying data between controls or even applications. Drag and drop would be a good fit if you're trying to allow a control to transfer between panels, for example.


    If you want to do both, then here's one possible idea:

    1. Perform move dragging within the same panel using your Mouse events.

    2. When you get a MouseLeave event on the panel, begin a DragDrop operation (some examples here) You can either remove the control from the panel or add some sort of 'gray out' effect to indicate that the control may be leaving.

    3. Handle the DragDrop on your target panel and place the control at the mouse location of the drop.

    This combines the intuitive feel of dragging the control around, while also providing a way to drag 'past' the panel and on to a new surface.

提交回复
热议问题