Drag and drop basics

C

Chris Leffer

I am trying to run a combination of some MS samples regarding drag and
drop. I want to copy or move data from a textbox depending on the
Keystate property, but my DragDrop event won't fire:

Private Sub txtOriginal_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles txtOriginal.MouseDown
txtOriginal.DoDragDrop(txtOriginal.Text, DragDropEffects.Copy Or
DragDropEffects.Move)
End Sub

Private Sub txtTarget_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles txtTarget.DragEnter

If e.KeyState = 1 Then 'No button is pressed
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If

ElseIf e.KeyState = 9 Then 'CTRL is pressed
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End If
End Sub

Private Sub txtTarget_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles txtTarget.DragDrop
Select Case e.KeyState
Case 1 'No button pressed, moves the data
txtTarget.Text = e.Data.GetData("Text")
txtOriginal.Text = String.Empty
Case 9 'CTRL pressed, copies the data
txtTarget.Text = e.Data.GetData("Text")
End Select

End Sub


What am I doing wrong here?

Regards,
Chris Leffer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top