Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net Drag andDrop from RichTextBox (Automatically grab all text)

Hi
I am using the following code to drag data from a RichTextBox. At the moment I have to click into the RichTextBox
and manually select the text. How do I alter the code so that all the text is automatically included in the drag without
having to manually select it

  Private Sub RichTextBox1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.StringFormat) Then
            ' Allow the drop.
            e.Effect = DragDropEffects.Copy
        Else
            ' Do not allow the drop.
            e.Effect = DragDropEffects.None
        End If

    End Sub

    Private Sub RichTextBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left And RichTextBox1.SelectionLength > 0 Then
            RichTextBox1.DoDragDrop(RichTextBox1.SelectedText, DragDropEffects.Copy)
        End If
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks very much