In the process of finding a solution for this question, a new question has appeared.
WinForms controls for working with Drag'n'Drop in .NET have several typical events and the DoDragDrop method.
But there are several problems associated with them. If we activate DoDragDrop on the DoDragDrop event, then until the drag process is complete, our program window does not receive mouse events, but receives events associated with the drag and drop procedure. While everything seems to be logical, but if after the dragging of the object is activated, the mouse does not move, the procedure does not end immediately, but with an indefinite timeout, and at this time mouse events are not transmitted to our window, which actually caused the problem described in the question above.
For TreeView and ListView it turned out there is a solution out of the box - the ItemDrag event, but for other controls that could potentially become a source for Drag'n'Drop, there is no such solution.
So far only one solution has occurred:
On the
MouseDowneventMouseDownraise the flag about the possible start of dragging and memorize the potential dragging object in the private fields of the form.On the
MouseMovecheck the flag and status of the mouse buttons, and if the specified conditions are met, call theDoDragDropmethod to the parameters of which to transfer the previously saved object as data for dragging. After that, reset the flag.
But for some reason it seems to me that this is a crutch, because depending on what and where we are going to drag, the code will differ and it will have to be duplicated for each form that requires such functionality.
Actually the question is, do I understand correctly that the drag and drop process is performed in the context of the operating system, rather than individual programs, in order to enable dragging and dropping objects between programs? If the assumption is correct, then is there a solution to bypass the listed problems more flexibly, without building bicycles of crutches? If my assumption is not true - then I would like to see in the answer how it actually works.
The question is addressed more likely to a WinAPI expert, but I would like to get a solution in the context of C #. In principle, for me, any solution that can be adapted for .NET is suitable, if it is better than what has already been stated.