DoDragDrop() from another thread

前端 未结 3 1949
情深已故
情深已故 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: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)
        {
        ...
        }
    ....
    }
    

提交回复
热议问题