467,075 Members | 912 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,075 developers. It's quick & easy.

Drag & Drop

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
Nov 20 '05 #1
  • viewed: 3521
Share:
3 Replies
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" <go******@netvision.net.il>
| Sender: "Goldwind" <go******@netvision.net.il>
| Subject: Drag & Drop
| Date: Sun, 31 Aug 2003 01:52:37 -0700
| Lines: 11
| Message-ID: <04****************************@phx.gbl>
| 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
|

Nov 20 '05 #2
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?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3
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.SelectionSta rt,
e.Data.GetData(System.Windows.Forms.DataFormats.Te xt, 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 @ <go******@netvisiob.net.il>
| References: <04****************************@phx.gbl>
| 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: <#C**************@TK2MSFTNGP11.phx.gbl>
| 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!TK2MSFTN GP11.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?
|
| *** Sent via Developersdex http://www.developersdex.com ***
| Don't just participate in USENET...get rewarded for it!
|

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Grey | last post: by
2 posts views Thread by Ivo Tcholakov | last post: by
6 posts views Thread by jojobar | last post: by
1 post views Thread by Terry Olsen | last post: by
3 posts views Thread by VB Programmer | last post: by
5 posts views Thread by sesar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.