wyDay blog  |  Downloads  |  Buy
LimeLM
wyBuild
Support forum
wyDay blog
wyDay Home

wyDay blog

October 20th, 2009

In todays tip Im going to cover showing drag & drop icons. Specifically keeping the icon overlay shown when you drag files from Windows Explorer to your .NET application. Heres a close-up of a user dragging files from a folder into wyBuild.

If we had used the normal .NET Framework interfaces for dragging files to wyBuild as soon as the cursor passes into the window the icons would disappear.

But, as you can see in the screenshot, the icons stay when dragging over our window. We can also set the drag & drop text to the current folder the user is dragging over.

How to add this to your app

This is one control I cant take credit for. Adam Root from Microsoft wrote up a nice control on his blog in a post Shell Style Drag and Drop in .NET - Part 3. The control works for both Windows Form and Windows Presentation Foundation (WPF) applications.

He wrote a 3 part series, and its interesting if you want to dig into the nitty-gritty Windows API.

How we use Drag & Drop in wyBuild

We use the Windows Form control in wyBuild, but we have to use a little trickery to get it work right. Because Adam wrote the Drag & Drop control using a .NET Framework 3.5 language feature, and wyBuild is built using .NET Framework 2.0, we have to use this little trick from Daniel Moth.

Just add this snippet of code to your project and youll be all set to go.

//HACK: this is to support a .NET language 3.5 feature in .NET 2.0
//see, http://www.danielmoth.com/Blog/2007/05/using-extension-methods-in-fx-20.html
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}

7 Days of Windows 7

Join me tomorrow when I talk about Using shield icons, UAC, and process elevation. See the full list of articles in the series.

Subscribe to our blog's RSS Feed or follow Wyatt (CEO of wyDay) on Mastodon (@wyatt@hachyderm.io) to keep up-to-date with our latest posts.

Comments