CallMeLaNN
CallMeLaNN

Reputation: 8578

C# Drag and Drop Effect with Overlay/Opaque Image

I think this would be simple question and should be asked in the pas few years but unable to google around and dont know if there is a specific keyword.

In c# WinForm I want to do drag and drop but I dont want the image of DragDropEffects Move, Copy or whatever. I want to display an image with half opaque. Just like Firefox when dragging an image, you would see the image folowing the mouse pointer like a ghost :)

I already Implement DoDragDrop, DragEnter and DragDrop events. I just want to customize the dragging effects with overlay image.

Upvotes: 5

Views: 4698

Answers (1)

Waescher
Waescher

Reputation: 5737

Might be 9 years too late to the party 😄

I always liked Drag&Drop interactions but found it complicated to use in WinForms. Especially if you want it to look professional with overlays.

I made my own library for WinForms the last time I needed Drag&Drop. You can find it here or on NuGet:

Drag and Drop operations with FluentDragDrop

Here's everything you need to implement Drag&Drop like shown above:

private void picControlPreviewBehindCursor_MouseDown(object sender, MouseEventArgs e)
{
    var pic = (PictureBox)sender;

    pic.InitializeDragAndDrop()
        .Copy()
        .Immediately()
        .WithData(pic.Image)
        .WithPreview().BehindCursor()
        .To(PreviewBoxes, (target, data) => target.Image = data);

    // Copy(), Move() or Link() to define allowed effects
    // Immediately() or OnMouseMove() for deferred start on mouse move
    // WithData() to pass any object you like
    // WithPreview() to define your preview and how it should behave
    //     BehindCursor() or RelativeToCursor() to define the preview placement
    // To() to define target controls and how the dragged data should be used on drop
}

Upvotes: 1

Related Questions