dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] Change Cursor During Drag and Drop

  1. #1

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,914

    Resolved [RESOLVED] Change Cursor During Drag and Drop

    I have a situation where a panel can have a fairly rich drawing on it containing regions, lines, and areas that are neither regions nor lines. Most things can be dropped anywhere on that panel, and everything could be made to work that way, but what I'm wondering is whether it is possible to change the cursor based on the element on the panel that the cursor is over during a drag event.

    I tried this out using the DragOver event for the panel, but nothing much happened. I was able to step through the code and ensure that the correct line was being called, but it didn't matter whether that correct line was:

    Cursors.Current = someNewCursor

    or

    panel.Cursor = someNewCursor

    Neither one changed a thing. I suppose the one thing I didn't try was toggling the AllowDrop property to False when the cursor passed over an area that wasn't allowed, but I don't believe that has a prayer of doing anything good. After all, I would expect that I couldn't toggle it back, and it likely wouldn't change anything anyways.

    Is there a reasonably easy way to accomplish this? If not, my plan B is to ignore the problem...which is always an easy solution, but not the best feedback. Heck, it might be a bad idea, anyways, but I'd still like to try it out if it is possible.
    My usual boring signature: Nothing

  2. #2
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,812

    Re: Change Cursor During Drag and Drop

    Hi Shaggy Hiker,

    I assume you've tried:

    Me.Cursor = someNewCursor

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  3. #3
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,282

    Re: Change Cursor During Drag and Drop

    Not attempted this in a long, long time, but isn't the GiveFeedback event used for this?

    The GiveFeedbackEventArgs Class has a UseDefaultCursors property that can be set to False.

  4. #4
    Lively Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    124

    Re: Change Cursor During Drag and Drop

    Hello,

    You should be able to find some clue here (see second answer) https://stackoverflow.com/questions/...op-vb-net-2010

    Regards

  5. #5

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,914

    Re: Change Cursor During Drag and Drop

    @Poppa: Yes, in a variety of ways, none of which worked.

    @Inferrd: I'm handling that, and you are right about UseDefaultCursors, but this goes well beyond that. I already don't use default cursors, but tinker around with them. This works well for moving over one control or another, as I get the cursors I want for each control. However, in this case I'm wanting different cursors when moving over different visual elements within a single control. It appears that GiveFeedback is going to be largely ineffective at that beyond what it is already doing. After all, it sounds like GiveFeedback is raised exactly once, and it certainly doesn't track location. I suppose I'm going off the documentation, and haven't confirmed that the documentation is correct, but I really believe that the event is raised only one time per control, during a drag event, in which case it has no chance of doing different things when covering different elements within the same control. That would require the event to be raised when the mouse moves, which it is not. DragOver seems more likely, since that IS raised as the item is dragged around on the control, but the cursor doesn't respond to changes.

    @Delaney: I had already seen that thread. The question is a good one, as it is pretty much on target for what I am wanting, but the answers are notably weak in that they don't solve the problem. The second answer added some information, it just didn't work, as it made no different whether I changed Control.Cursor, or Cursors.Current.
    My usual boring signature: Nothing

  6. #6
    Lively Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    124

    Re: Change Cursor During Drag and Drop

    I was wondering (but it may be a beginner question), when you drag your element, do you keep the mouse button down ? because in that case you should be still in the "mouse button down" event and maybe you cannot raise any other event when you pass over others elements?

  7. #7
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,282

    Re: Change Cursor During Drag and Drop

    Quote Originally Posted by Shaggy Hiker View Post
    .... it sounds like GiveFeedback is raised exactly once, and it certainly doesn't track location.
    GiveFeedBack should be raised whenever the mouse moves, although it is only raised by the control where the drag was started.

    No, it doesn't track location. You have to write code to do that yourself. I've no idea how you are recognising the different lines/regions drawn on your panel so can't comment on how you'd do the tracking, but PointToClient(MousePosition) (called in the GiveFeedBack handler) is useful for determining the whereabouts of the mouse cursor in the relevant panel.

    I have tested it, and can certainly get the cursor to change as I drag around inside a panel.

  8. #8

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,914

    Re: Change Cursor During Drag and Drop

    Quote Originally Posted by Delaney View Post
    I was wondering (but it may be a beginner question), when you drag your element, do you keep the mouse button down ? because in that case you should be still in the "mouse button down" event and maybe you cannot raise any other event when you pass over others elements?
    You have to have the mouse button down during a drag, that's how it works. Drag events DO get raised during that time.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,914

    Re: Change Cursor During Drag and Drop

    Quote Originally Posted by Inferrd View Post
    GiveFeedBack should be raised whenever the mouse moves, although it is only raised by the control where the drag was started.

    No, it doesn't track location. You have to write code to do that yourself. I've no idea how you are recognising the different lines/regions drawn on your panel so can't comment on how you'd do the tracking, but PointToClient(MousePosition) (called in the GiveFeedBack handler) is useful for determining the whereabouts of the mouse cursor in the relevant panel.

    I have tested it, and can certainly get the cursor to change as I drag around inside a panel.
    That part is easy. It sounds like I may have misread the documentation on GiveFeedback. I hope to try it out in a few hours.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,914

    Re: [RESOLVED] Change Cursor During Drag and Drop

    It took me two tries (cause I worked on the wrong GiveFeedback event handler, the first time), but it did work, as expected. One little quirk that I noted was that, once I had changed the cursor, it remained changed, even after the drop had happened. Solving that was just a matter of setting the cursor back in the drop event handler.

    It's an interesting point. Thanks for all who contributed.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width