Fair enough, rather than debate the design pros and cons I think this code
is what you're looking for.
Note: This will only work for RichTextBox controls and not standard
textboxes. The reason being that a standard textbox loses it's selectedtext
BEFORE the mousedown event gets processed.
Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
RichTextBox1.Text =
RichTextBox1.Text.Insert(RichTextBox1.SelectionStart,
e.Data.GetData(System.Windows.Forms.DataFormats.Text, True))
End Sub
Private Sub RichTextBox2_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles RichTextBox2.MouseDown
If RichTextBox2.SelectedText.Length > 0 Then
Dim s As String = RichTextBox2.SelectedText
RichTextBox2.DoDragDrop(s, DragDropEffects.Copy)
End If
End Sub
Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Cameron McColl
Microsoft
--------------------
| From: Goldwind @ <
[email protected]>
| References: <
[email protected]>
| X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
| Subject: Re: Drag & Drop
| Mime-Version: 1.0
| Content-Type: text/plain; charset="us-ascii"
| Content-Transfer-Encoding: 7bit
| Message-ID: <#
[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| Date: Wed, 03 Sep 2003 00:56:51 -0700
| NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:133713
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Cameron,
|
| I think the Drag & Drop, in this case, may simplify the work of a user.
| What is prefered?
| 1) select text -> do copy -> go to the other field -> do paste
| OR
| 2) select text -> drag to the other field
|
| When you drag an image control which present an image object, you dont
| mean to accept the all control. you want in only to transfer the image.
| same with listbox and treeview etc. in these two cases, you are not
| interested in draging a line, you are interested in transferring their
| text.
| (We did got a positive feedbacks from users)
|
| Is There a technical solution to this problem, in the current version of
| .Net 2003?
|
|
| Don't just participate in USENET...get rewarded for it!
|