Displaying a bitmap AND mouse cursor while dragging

Willy V 20 Reputation points
2024-02-12T14:26:10.22+00:00

Hi,

In VB I can drag and drop an item between two lists without any problems but even after extensive searching I haven't found a convincing method to show the user what is being dragged.

This could of course be me using less than optimal search terms but it still surprises me as it is something we see everywhere around us. I therefore expected to easily find results about this technique.

For example, when I drag a file in File Explorer I see a transparent icon depending on the file type. When I drag an e-mail item from Outlook's Inbox to another folder I see a transparent line with the e-mail's topic and other information.

I know how to change the mouse cursor to a bitmap having full information about the item being dragged. But this isn't really helpful as the mouse cursor itself and its display of DragDropEffects is gone.

In the above examples both the mouse cursor and a bitmap showing information about the item being dragged are shown.

The DoDragDrop method mentions an overload which suggests a bitmap could be included:

DoDragDrop(Object, DragDropEffects, Bitmap, Point, Boolean)

However, this overload is not available when I insert the method in my code and I haven't found any examples of how to use it. I can only access this one:

DoDragDrop(Object, DragDropEffects)

I could use a PictureBox, set it up with the desired information bitmap and move it around together with the mouse cursor but I suspect there are better practices. So before I take that route, what is the usual way to achieve this? I'd appreciate any suggestions (and possibly examples) to point me in the right direction. Willy

Developer technologies .NET Other
Developer technologies VB
{count} votes

Accepted answer
  1. Michael Taylor 60,161 Reputation points
    2024-02-12T15:17:54.85+00:00

    The DoDragDrop overload you mentioned is only available in .NET 4.8.1+. You need to target that framework to get it. Although the functionality itself was available since Win7 so if you cannot target .NET 4.8.1 then you could create your own import that does the same thing.

    Personally I would recommend that you go look at the code for the implementation in .NET 4.8.1 and just copy it. Hopefully it doesn't require anything that is only in the newer version but I sort of doubt it.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.