Showing posts with label Drag-and-Drop. Show all posts
Showing posts with label Drag-and-Drop. Show all posts

Drag-and-Drop Not working When Debugging in Visual Studio Under Windows Vista

Tuesday, October 30, 2007

There are many programmers out there working on real-world applications who have not programmed drag-and-drop functionality. However, sooner or later, you will need this nice feature of Windows (and GUI in general).

Adding drag-and-drop support to your application is not difficult in C#/.NET. However, when it comes to debugging drag-and-drop under Windows Vista that's when trouble begins. If drag-and-drop does work fine when you run the application from Explorer but does not when you run from Visual Studio 2005 don't be surprised. We will demystify this quickly. However, I must admit that it took me about and hour to figure out what was wrong.

As you are well aware, under Windows Vista, we usually work from a low privilege account. However, because this causes some problems when working in Visual Studio, most of the programmers run Visual Studio with Administrator privileges. It turns out that Windows Vista does not allow drag-and-drop operation if you are dragging from a lower privilege application to one with administrator privileges. So now it's easy to explain the strange behaviour.

When you start the application in a debug mode, Visual Studio has administrator privileges and if you try to drag-and-drop say from your desktop (which most likely has low privileges) the operation fails. Visual Studio would not even fire the drag-and-drop events.

So, what do we do when we need to run Visual Studio under administrator privileges and yet be able to debug drag-and-drop? Well, now when we have demystified the strange behaviour, we can solve this problem. This is how I solved this. I use Total Commander as my File Manager. So I run both Total Commander and Visual Studio with administrator privileges and drag-and-drop debugging works just fine.

Happy programming!

More cool posts coming soon.