Search code examples
vb.netdrag-and-dropmouse-cursor

Change Cursor as Feedback in DragDrop VB.NET 2010


Working on a DragDrop application. I have a class object (built as an object) which has a GroupBox that is enabled for DragDrop.

In the class I have set it up so that the cursor will change when it enters the groupbox, leaves the groupbox, mouse is down within the groupbox and drag/drop is working. I also set up a label in the class object and changed the text in that label as well. Basically, the text changes in the label as expected including 'FEEDBACK' appearing when I am dragging the object BUT the cursor stays stubbornly as a pointer. This is tghe state of affairs either when I debug the class or when, after I build the class, it is run as part of the main program.

Here are the subs set up in the class.

Private Sub GroupBoxSourceMouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseDown
    GroupBoxSource.DoDragDrop(GroupBoxSource.Text, DragDropEffects.Copy)
    lbl1.Text = "DOWN"
End Sub

Private Sub GroupBoxSourceMouseMove(ByVal sender As Object, ByVal e  AsSystem.Windows.Forms.MouseEventArgs) Handles GroupBoxSource.MouseMove
    If bolDragDropMouseDown Then
        ' Initiate dragging.
        'GroupBoxSource.DoDragDrop(GroupBoxSource.Text, DragDropEffects.Copy)
    End If
    bolDragDropMouseDown = False
    lbl1.Text = "MOVE"
End Sub

Private Sub GroupBoxSourceMouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseEnter
    Windows.Forms.Cursor.Current = Cursors.Hand
    lbl1.Text = "ENTER"
End Sub

Private Sub GroupBoxSourceMouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBoxSource.MouseLeave
    Windows.Forms.Cursor.Current = Cursors.Arrow
    lbl1.Text = "LEAVE"
End Sub

Private Sub GroupBoxSourceDragDropFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles GroupBoxSource.GiveFeedback
    Windows.Forms.Cursor.Current = Cursors.SizeAll
    lbl1.Text = "FEEDBACK"
End Sub

Now for the unusual stage. I decided to change the cursor during FormLoad of the main program (which has the class object defined on the form) to a hand and nothing changed. In desperation I set up a 1mS timer and coded that to change the cursor to a hand and sure enough the cursor is now a hand but momentarity flicks back to a pointer when I move the cursor so it looks as if something else is causing the cursor to revert to its default value.


Solution

  • To easily change the cursor, click on the form and bring up the properties. Then go to Cursor and change it to whatever you want.