Drag & Drop

  • Thread starter Thread starter Goldwind
  • Start date Start date
G

Goldwind

Hi,

I"m trying to use drag & drop of text from one text box to
another but without suceess.
Microsoft presented an example in "101 code samples" BUT
in this example the code select and drag all the text in
the TextBox, wether the user wants or not.
I need to drag only the selected text (changing the
example causes it not to work).

Thanks in advance
 
I don't think what you're trying to do is a good idea.
DragDrop is really a concept for objects.
For text Cut/Copy/Paste is the default solution.

Suppose you did succeed in implementing Drag and Drop for the selected
text. Think about the user experience.
They want to try and select a different range of text and instead when they
hold the mouse down your dragdrop begins. This would be quite frustrating
for customers.

Cameron McColl
Microsoft


--------------------
| Content-Class: urn:content-classes:message
| From: "Goldwind" <[email protected]>
| Sender: "Goldwind" <[email protected]>
| Subject: Drag & Drop
| Date: Sun, 31 Aug 2003 01:52:37 -0700
| Lines: 11
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcNvnTqRPAdJPoPZQMqN4Wf2Y7GmQA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.vb
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:132773
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Hi,
|
| I"m trying to use drag & drop of text from one text box to
| another but without suceess.
| Microsoft presented an example in "101 code samples" BUT
| in this example the code select and drag all the text in
| the TextBox, wether the user wants or not.
| I need to drag only the selected text (changing the
| example causes it not to work).
|
| Thanks in advance
|
 
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?
 
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!
|
 
Back
Top