共用方式為


Shell Style Drag and Drop in .NET - Part 2

Last week, in Shell Style Drag and Drop in .NET (WPF and WinForms), I looked at hooking up the COM interfaces necessary to implement drag images using the Windows Shell. This week, I'm going to introduce some .NET 3.5 extensions (which can be easily converted into .NET 3.0 and earlier static helper functions) that reduce the code overhead of implementing great drag and drop preview images in your .NET applications.

Read More ...

Comments

  • Anonymous
    February 11, 2008
    This is great and very helpful. I have also followed your Part 1 and like the way you have explained all the details of various methods and implementations. Is it OK to go ahead and use the LIB you have created in our projects?

  • Anonymous
    February 11, 2008
    Adam, I tried using this code in my application, but hit a roadblock since i was trying to add this  logic to user control and not to the main windows. The DragHelper methods expect a Window. I am trying to dig further to see what i can do to handle this. but if you have any suggestions, do share.

  • Anonymous
    February 12, 2008
    The thing about WPF, is that you only have a window handle, which we need when calling the COM interfaces, at the Window level. All the WPF visual elements are custom drawn, and are not "windows" in the sense of Win32 programming, which is what WinForms was built on. So, in WPF, you can use your parent Window when working with the DropTargetHelper.DragEnter method. Or, you could try passing null for the Window param, but I don't fully understand what is happening when you do that. It has worked for me, though. Regardless, the underlying COM interface expects a window handle, which your UserControl doesn't have.

  • Anonymous
    February 12, 2008
    Just wanted to throw this out there. In coming up with these blog posts, my examples don't pass actual data to the DataObject instance. Once you set a COM IDataObject instance as the interal data store to a .NET DataObject, you can no longer use the .NET SetData function. I address this in my next post, Shell Style Drag and Drop in .NET - Part 3