I have a bunch of text boxes that I want to be able to drag and drop the text in them to each other. I have the drag and drop able to copy the text of one text box into another but I need it to clear the original text box if there is nothing in the target text box or if there is something in the target text box copy that value into the original text box.
I'm working with Visual Studio 2005.
Here is the code for it where txtRoll1 is the text box being dragged to txtStr and MouseDown is a global variable initialized to false when the form loads
Private Sub txtRoll1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtRoll1.MouseDown
MouseIsDown = True
End Sub
Private Sub txtRoll1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtRoll1.MouseMove
If MouseIsDown Then
txtRoll1.DoDragDrop(txtRoll1.Text, DragDropEffects.Copy)
End If
MouseIsDown = False
End Sub
Private Sub txtStr_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtStr.DragDrop
txtStr.Text = e.Data.GetData(DataFormats.Text).ToString
End Sub
Private Sub txtStr_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtStr.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub