How to drag the selected text from a textbox?

J

John Smith

How to drag the selected text from a textbox?

I know how to drag the full text from a textbox.
I don't want to use the richtextbox.
 
C

Cor

Hi John,

From textbox1 to textbox2

I hope this helps?

Cor

\\\The most part copied from MSDN
Private MouseIsDown As Boolean = False
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox2.AllowDrop = True
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
MouseIsDown = True
Me.TextBox1.SelectAll()
Me.TextBox1.Cursor = Cursors.Hand
End Sub
Private Sub TextBox1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove
If MouseIsDown Then
TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
End If
MouseIsDown = False
Me.TextBox1.Cursor = Cursors.Default
End Sub
Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
TextBox2.Text = e.Data.GetData(DataFormats.Text).ToString
End Sub
///
 
J

John Smith

well, i need to drag only one selected word and drop this word into an
existing text without replacing the whole text.

example
textbox2.text is:
Hey. How are you?
textbox1.text is:
Hello Cor. How are you?
i select Cor for dragging and drag it to textbox2 so that it becomes:
Hey Cor. How are you?
 
J

John Smith

Thanks again Cor

I believe that subclassing the control is the only solution for now
Maybe vb2005 comes with a full drag and drop support
 

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

Similar Threads


Top