C#拖放效果与叠加/不透明图像

Cal*_*aNN 4 c# overlay drag-and-drop winforms

我认为这将是一个简单的问题,应该在几年内问,但无法谷歌周围,不知道是否有一个特定的关键字.

在c#WinForm中我想拖放但我不想要DragDropEffects Move,Copy等等的图像.我想要显示半透明的图像.就像Firefox拖动图像一样,你会看到像鼠标一样的鼠标指针图像:)

我已经实现了DoDragDrop,DragEnter和DragDrop事件.我只想用叠加图像自定义拖动效果.

Bin*_*nil 5

校验

在.NET中的Shell样式拖放

希望这可以帮助


Wae*_*her 0

参加派对可能晚了9年

我一直喜欢拖放交互,但发现它在 WinForms 中使用起来很复杂。特别是如果您希望它通过叠加看起来很专业。

上次我需要拖放时,我为 WinForms 制作了自己的库。您可以在此处或 NuGet 上找到它:

使用 FluentDragDrop 进行拖放操作

这是实现拖放所需的一切,如上所示:

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
}
Run Code Online (Sandbox Code Playgroud)