Jump to content
  • Advertisement
Sign in to follow this  
ArchG

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

This topic is 3738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!