DoDragDrop() from another thread

前端 未结 3 1913
情深已故
情深已故 2021-01-27 09:02

Every time i want let the user to drag an control, i calling DoDragDrop of that control.

The drag & drop works fine, but i have problem with things around:

相关标签:
3条回答
  • 2021-01-27 09:16

    You need to forget about using a thread, that's only going to deliver D+D notifications to the windows that were created on that thread. Which will not be your controls.

    I can't do much with a "code is sucks" diagnostic. The DoDragDrop() call itself will indeed block until the mouse button is released. Another message loop, internal to COM code will take over and deliver the Windows messages. Timer and paint messages should be delivered as normal. A diagnostic is very hard to come by until you post some repro code.

    0 讨论(0)
  • 2021-01-27 09:34

    You probably want the DoDragDrop to quit and do the job asynchronously.

    Here is the answer.

    0 讨论(0)
  • 2021-01-27 09:35

    The DoDragDrop method stops processing of events until first mouse event (for example mouse move). So the workaround I found is very simple - you just need to simulate mouse event with the same mouse position just before calling DoDragDrop:

    
    void XYZControl_MouseDown(object sender, MouseEventArgs e)
    {
        var senderControl = (Control) sender;
        ...
        Cursor.Position = senderControl.PointToScreen(new Point(e.X, e.Y));   // Workaround!
        if (DoDragDrop(senderControl, DragDropEffects.Move) == DragDropEffects.Move)
        {
        ...
        }
    ....
    }
    
    0 讨论(0)
提交回复
热议问题