drag and drop like word does

  • Thread starter Thread starter tgillispie
  • Start date Start date
T

tgillispie

I am trying to get the drag and drop in C# to work like it does in Word. I
have a list box, and I am dragging/dropping an item from it into a text box.
What I would like to see happen is that wherever the mouse is when I drop,
that is where the textbox.selectionStart begins. I can get he cursor
location, but I cannot convert that into a coordinate in the textbox. Thanks
in advance.

Travis
 
Hi tgillispie,

Unfortuantely, .NET TextBox doesn't support finding the character position
from coordinates. You can do it by sending the text box EM_CHARFROMPOS
message using P\Invoke.

Anyway, my suggestion is to consider using RichTextBox insted.
RichTextControl has a method called GetCharFromPosition and you can find the
position where to insert the dropped text. Don't forget to convert the
screen coordinates from DragEventArgs to RichTextBox's client coordiantes
(RichTextBox.PointToClient(pt)).

HTH
B\rgds
100
 
Back
Top