Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support drag and drop with icon and text label #5884

Closed
ghost opened this issue Sep 30, 2021 · 74 comments Β· Fixed by #6576
Closed

support drag and drop with icon and text label #5884

ghost opened this issue Sep 30, 2021 · 74 comments Β· Fixed by #6576
Assignees
Labels
api-approved (4) API was approved in API review, it can be implemented api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation

Comments

@ghost
Copy link

ghost commented Sep 30, 2021

πŸ’₯ πŸ’₯ ⬇️⬇️ Scroll to the API proposal ⬇️⬇️πŸ’₯ πŸ’₯


About Winform drag and drop:
https://docs.microsoft.com/en-us/dotnet/desktop/winforms/input-mouse/drag-and-drop

Winforms supports drag and drop, but it displays the Windows 2000/XP old school style.

003

Unlike win10, win10 can provide richer display effects. If you drag and drop a file on Win10, Win10 will display an icon and a text label. Then you can know your specific operation through the text label.

Picture 1: Drag a file:

001

Picture 2: When you hold down the Control or Alt key, the icon and text will also be changed.

002-2

Picture 3: Drag a file to application shortcut, it will display:

004

So if the drag and drop can provide an Icon and Text properties, the application can display a more detailed operating instruction to users, and the application will be more modern.

@ghost ghost added the api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation label Sep 30, 2021
@RussKie

This comment has been minimized.

@RussKie RussKie added πŸ“­ waiting-author-feedback The team requires more information from the author and removed api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation labels Sep 30, 2021
@ghost

This comment has been minimized.

@ghost ghost removed the πŸ“­ waiting-author-feedback The team requires more information from the author label Oct 1, 2021
@wjk
Copy link
Contributor

wjk commented Oct 6, 2021

Drag images can be created today via the IDragSourceHelper interface. Similarly, drop text can also be created today using the DROPDESCRIPTION structure and clipboard format, as demonstrated here. Use of either requires a custom IDataObject implementation because of limitations in the standard Windows Forms one; the latter link provides an example. It would be quite nice if this functionality could be rolled into Windows Forms core.

Note that the drag source supplies the image, but the drop destination supplies the text and icon. You cannot provide label text from a drag source.

@ghost
Copy link
Author

ghost commented Oct 7, 2021

Drag images can be created today via the IDragSourceHelper interface. Similarly, drop text can also be created today using the DROPDESCRIPTION structure and clipboard format, as demonstrated here. Use of either requires a custom IDataObject implementation because of limitations in the standard Windows Forms one; the latter link provides an example. It would be quite nice if this functionality could be rolled into Windows Forms core.

Note that the drag source supplies the image, but the drop destination supplies the text and icon. You cannot provide label text from a drag source.

I can see this API from microsoft website.

IDragSourceHelper2::SetFlags with flag DSH_ALLOWDROPDESCRIPTIONTEXT

https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-idragsourcehelper2-setflags

It will display the drag image and text at the same time.

@RussKie
Copy link
Member

RussKie commented Oct 8, 2021

Would you like to do a formal API proposal so we can take it to the next level? If you have a POC - it would greatly aid in discussions.

@RussKie RussKie added the api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation label Oct 8, 2021
@RussKie RussKie added this to the Future milestone Oct 8, 2021
@RussKie RussKie added the πŸ“­ waiting-author-feedback The team requires more information from the author label Oct 8, 2021
@ghost
Copy link
Author

ghost commented Oct 14, 2021

@wjk Can you help me to fill the formal API proposal? My English is not very good. Thank you very much.

@ghost ghost removed the πŸ“­ waiting-author-feedback The team requires more information from the author label Oct 14, 2021
@willibrandon
Copy link
Contributor

Good idea.

@willibrandon
Copy link
Contributor

willibrandon commented Nov 1, 2021

New school style drag and drop.

DragImageText

@ghost
Copy link
Author

ghost commented Nov 2, 2021

Yes, that's a perfect effect.

In this way, more data and hints can be displayed to users.

@willibrandon
Copy link
Contributor

@roland5572 - you have really good ideas.

@ghost
Copy link
Author

ghost commented Nov 2, 2021

Thank you. I also have some ideas about WPF, if you are interested, you can check it out.

dotnet/wpf#5565
dotnet/wpf#5566

@willibrandon
Copy link
Contributor

willibrandon commented Nov 2, 2021

I will check those out.

For this issue, has any progress been made on a proposal?

@willibrandon
Copy link
Contributor

willibrandon commented Nov 4, 2021

Okay then if nobody minds, I will take a closer look. I need to learn quite a bit more about drag and drop before I would be comfortable suggesting anything but I think with a little focus it is doable. Drag image and text.

@RussKie
Copy link
Member

RussKie commented Nov 4, 2021 via email

@willibrandon
Copy link
Contributor

Alpha blended drag image.

nyancat_alphablended

@willibrandon
Copy link
Contributor

willibrandon commented Nov 8, 2021

Drag image with drop description proof of concept.

DragImageDropDescription.mp4

@merriemcgaw
Copy link
Member

This is awesome stuff! Have you thought about whether we should support for dragging something with a drag source outside of the application? Like picking up a file from Windows to copy into your app.

@willibrandon
Copy link
Contributor

Thanks, its been really fun. I think adding support for drag images and drop descriptions for drag sources outside of the application would be really helpful. It would allow the application to display more details to the user regarding the drag-and-drop operation.

@willibrandon
Copy link
Contributor

willibrandon commented Nov 9, 2021

Drag images and drop descriptions from Explorer.

DragCatFromExplorer.mp4

@RussKie
Copy link
Member

RussKie commented Nov 10, 2021

Awesome!
Standing by for your API proposal. Feel free to open a draft PR to accompany it as well.

@willibrandon
Copy link
Contributor

This will be a stretch for me but I'll start putting it together. I believe there are some other subtler features I haven't looked at yet such as the mouse cursor offset in relation to the drag image and how that allows for some cool things like insertion points with previews.

@willibrandon
Copy link
Contributor

willibrandon commented Nov 10, 2021

Note that the outer edges of the drag image are blended out if the image width or height exceeds 300 pixels.

DragImageEdgeBlend

@RussKie RussKie added the api-ready-for-review (2) API is ready for formal API review; applied by the issue owner label May 2, 2022
@RussKie RussKie modified the milestones: Future, .NET 7.0 May 2, 2022
@RussKie RussKie added the waiting-on-team This work item needs to be discussed with team or is waiting on team action in order to proceed label May 2, 2022
@merriemcgaw merriemcgaw added the blocking Used by the API Review Board label May 2, 2022
@merriemcgaw merriemcgaw modified the milestones: .NET 7.0, 7.0 Preview5 May 2, 2022
@RussKie RussKie removed the waiting-on-team This work item needs to be discussed with team or is waiting on team action in order to proceed label May 2, 2022
@terrajobst
Copy link
Member

terrajobst commented May 3, 2022

Video

  • DropImageType
    • We should align the names of DropImageType with Windows terminology, which includes using Image over Icon
      • Default -> Invalid
      • NoDrop -> NoImage
  • DragEventArgs
    • DropIcon to DropImageType
    • The Message* properties should probably be nullable
  • GiveFeedbackEventArgs
    • The constructor should match DoDragDrop with respect to nullability of bitmap, so we should probably make it non-nullable
namespace System.Windows.Forms;

public enum DropImageType
{
    Invalid = -1,
    None = 0,
    Copy = DragDropEffects.Copy,
    Move = DragDropEffects.Move,
    Link = DragDropEffects.Link,
    Label = 6,
    Warning = 7,
    NoImage = 8
}

public class DragEventArgs : EventArgs
{
    // Existing:
    // public DragEventArgs(IDataObject? data, int keyState, int x, int y, DragDropEffects allowedEffect, DragDropEffects effect);

    public DragEventArgs(IDataObject? data, int keyState, int x, int y, DragDropEffects allowedEffect, DragDropEffects effect, DropImageType dropIcon, string message, string insert);

    // Existing:
    // public IDataObject? Data { get; }
    // public int KeyState { get; }
    // public int X { get; }
    // public int Y { get; }
    // public DragDropEffects AllowedEffect { get; }
    // public DragDropEffects Effect { get; set; }

    public DropImageType DropImageType { get; set; }
    public string? Message { get; set; }
    public string? MessageReplacementToken { get; set; }
}

public class GiveFeedbackEventArgs : EventArgs
{
    // Existing:
    // public GiveFeedbackEventArgs(DragDropEffects effect, bool useDefaultCursors);

    public GiveFeedbackEventArgs(DragDropEffects effect, bool useDefaultCursors, Bitmap? dragImage, Point cursorOffset, bool useDefaultDragImage);

    // Existing:
    // public DragDropEffects Effect { get; }
    // public bool UseDefaultCursors { get; set; }

    public Bitmap? DragImage { get; set; }
    public Point CursorOffset { get; set; }
    public bool UseDefaultDragImage { get; set; }
}

public partial class Control
{
    // Existing:
    // public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects);

    public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects, Bitmap dragImage, Point cursorOffset, bool useDefaultDragImage);
}

public partial class ToolStripItem
{
    // Existing:
    // public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects);

    public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects, Bitmap dragImage, Point cursorOffset, bool useDefaultDragImage);
}

@terrajobst terrajobst added api-approved (4) API was approved in API review, it can be implemented and removed api-ready-for-review (2) API is ready for formal API review; applied by the issue owner labels May 3, 2022
@RussKie RussKie removed the blocking Used by the API Review Board label May 3, 2022
@willibrandon
Copy link
Contributor

That is awesome. I agree with the suggested changes and will start working on updating the proposal and draft PR.

Thank you everyone for taking a look at this. I understand that time is short and I greatly appreciate everyone's effort on this issue.

@Olina-Zhang
Copy link
Member

@willibrandon Is this work completed? Since we saw the related PR is merged and tested it in the latest .Net 7.0 build.

@ghost ghost removed the 🚧 work in progress Work that is current in progress label Jul 25, 2022
@RussKie
Copy link
Member

RussKie commented Jul 25, 2022

Yes, @Olina-Zhang, this has been resolved by #6576.
Thank you for the nudge.

@RussKie RussKie closed this as completed Jul 25, 2022
@ghost ghost removed this from the 7.0 Preview7 milestone Jul 25, 2022
@Olina-Zhang
Copy link
Member

Verified on .NET 7.0 test pass build: .NET 7.0.100-preview.7.22370.3, issue was fixed: it supports dragging and dropping pictures and RTF files now.

@willibrandon
Copy link
Contributor

willibrandon commented Aug 18, 2022

@roland5572 - I'm not sure how we're going to top this one. Good idea.

@RussKie
Copy link
Member

RussKie commented Aug 19, 2022

Haha, we have plenty of issue in the back log πŸ˜‰ I'm sure you can find something to your taste there, e.g.: api-approved (4) API was approved in API review, it can be implemented and https://github.com/dotnet/winforms/labels/up-for-grabs

Thanks again for your contributions.

@dotnet dotnet locked as resolved and limited conversation to collaborators Sep 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved (4) API was approved in API review, it can be implemented api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants