Sign in to follow this  
ArchG

[.net] Dragging and Dropping in C# (changing the cursor)

Recommended Posts

Hello, I've got a C# Windows form application that contains a couple controls, one being the System.Windows.Forms.WebBrowser object, and another being a System.Windows.Forms.ToolStrip object. I've added some drag and drop functionality, so when you drag a link from the WebBrowser object, to the ToolStrip object, it executes some different functions(not important what it does). It works fine, the problem is, that the Cursor is always Cursors.No (the not allowed cursor), I've tried many things to change it, but I'm not sure what I'm doing wrong. Here is some of my code. The Constructor
toolStrip.AllowDrop = true;

toolStrip.DragEnter += new DragEventHandler(toolStrip_DragEnter);
toolStrip.DragOver += new DragEventHandler(toolStrip_DragOver);
toolStrip.DragDrop += new DragEventHandler(toolStrip_DragDrop);


Event Handlers
void toolStrip_DragOver(object sender, DragEventArgs e)
{
     e.Effect = DragDropEffects.All;
     footerStrip.Cursor = Cursors.Hand; //has no effect
}

void toolStrip_DragDrop(object sender, DragEventArgs e)
{
     //handle drag & drop
}

void toolStrip_DragEnter(object sender, DragEventArgs e)
{
     e.Effect = DragDropEffects.All;
}


I've tried overriding OnGiveFeedback(), but it never seems to get executed. The funny thing is, is that the cursor changes to the default copy cursor, if I drag a link from an external web browser (like firefox)...but if i drag something from the WebBrowser control within the application, it doesn't. I'm not sure if this is just a problem with the WebBrowser control, or if I'm doing something wrong. Thanks

Share this post


Link to post
Share on other sites
First you must set the AllowDrop on the target control to true.

then set the Effect property on the DragEventArgs object received to to one of the allowed effects that is returned by the AllowedEffect property. In your case a drag operation of a link has an allowed effect of Link.

void toolStrip_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Link;
}

should do it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this