Drag drop in RichTextBox

J

Jerry

Hi,

I find some strange thing when I use drag drop in RichTextBox control. I
create a control inherit RichTextBox.:

1. In OnDragEnter and OnDragOver, AllowDragDropEffect of DragEventArgs
is DragDropEffects.All always.
2. I can't find where I can set the DragDropEffect when I do drag drop
in RichTextBox.

Who can help me? thanks.

Jerry
 
L

Lance Johnson

This appears to be the tricky part. For some reason, they have neglected to
implement the code for dragging items from a richtextbox. I've been working
on this recently but am not entirely sure this is accurate. Maybe somebody
can help us out on this. To begin with, there's a certain dragsize that has
to occur before a drag operation. You can find that in
SystemInformation.DragSize.

1) Override the mousedown method and if mouse is over selected text set a
variable to know the rectangle area to not be considered a drag operation.
To do this, get the index by GetCharIndexFromPosition and then see if it's
in the range of selection. Make sure something is selected first.
2) Override the mousemove method and if the left mouse is down and the
dragging area is not empty and the current position is outside of the
rectangle area set from mousedown, you can begin a drag operation. Look at
the method DoDragDrop. Upon return from this, I'd reset the rectangle area
to empty.

Hope this helps some and I hope I'm on the right track also.

Lance Johnson
 
J

Jerry

Thank you for your answer. I have realized the drag drop by a simple method:
just
override OnDragEnter, OnDragOver and OnDragDrop. But I can't get the effect
I expect:
Drag effect is Copy when I drag a item from another control(for example,
from a TreeView),
Because the AllowDragDropEffect that I get in OnDragEnter and OnDragOver is
DragDropEffects.All always. I can't sure the drag operation is from another
control or itself.
Do you have an ideal about it? Thank again.

Jerry
 

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

Top