Results 1 to 3 of 3

Thread: [RESOLVED] Tab control - Change cursor while dragging

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    575

    Resolved [RESOLVED] Tab control - Change cursor while dragging

    Hi,

    I've implemented Drag & Drop in Tab control and I want cursor to be changed while dragging Tabs. I got that part too, but with one slight problem - normally you change cursor on GiveFeedback event when you allready started drag drop action. Unfortunally I also set start of drag/drop in Mousedown, so when I click to change Tab page my new dragging cursor also appears for a moment, because left mouse click was done. Is there any way that I could start drag/drop with left mouse after I changed Tab page, and then change cursor ?

    My code:

    Code:
      Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
            MyBase.OnMouseDown(e)
    
         'Current tab is checked in MouseMove, and It's added into Tag
                If Not Me.Tag Is Nothing Then
    
                    Dim clickedTab As TabPage = DirectCast(Me.Tag, TabPage)
                    Dim clicked_index As Integer = Me.TabPages.IndexOf(clickedTab)
    
                    ' start drag n drop
                    Me.DoDragDrop(clickedTab, DragDropEffects.All)
    
                End If
    
        End Sub
    
    
        Protected Overrides Sub OnGiveFeedback(gfbevent As GiveFeedbackEventArgs)
            MyBase.OnGiveFeedback(gfbevent)
    
            ' Set the custom cursor based upon the effect.
            gfbevent.UseDefaultCursors = False
    
            If ((gfbevent.Effect And DragDropEffects.Move) = DragDropEffects.Move) Then
                Cursor.Current = Cursors.Hand
            Else
                Cursor.Current = Cursors.Default
                End If
    
        End Sub
    Last edited by LuckyLuke82; Jun 9th, 2017 at 07:13 AM.

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Tab control - Change cursor while dragging

    Generally you shouldn't start a "drag" operation on MouseDown because of problems like this. Every click starts a drag and drop operation, and that can cause weird things to happen.

    The more correct way to start a drag and drop operation is to start it after the mouse is down *and* has moved by a certain margin. It turns out "a certain margin" is defined by SystemParameters.MinimumHorizontalDragDistance and SystemParameters.MinimumVerticalDragDistance. So you need to write something like this:
    Code:
    When MouseDown happens:
        * Note the position of the cursor.
    
    When MouseUp happens:
        * If a drag/drop is in progress:
            * Do the thing.
        * Note a drag/drop can't be happening anymore.
    
    When MouseMove happens:
        * If the user is holding the button and a drag/drop isn't already in progress:
            * If the mouse has moved far enough:
                * Note a drag/drop is happening, update the cursor, and save any information you might need.
    The documentation for DoDragDrop() has a pretty good implementation, though it looks like in theirs they drag things during MouseMove (which is sensible sometimes.)
    Last edited by Sitten Spynne; Jun 12th, 2017 at 09:10 AM.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    575

    Re: Tab control - Change cursor while dragging

    Thanks Sitten,

    very good example, didn't notice this solution at all. I've implemented drag operation in simmilar (but much simpler) way and It works good

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width