M
MySelf
Hello,
I am working on an application including a drag and drop feature
between a TreeView and a RTF Text box. But I have a problem : when
there is already a string in the RTF Text Box ("ABCDEF" for example),
and if I drop the new string (coming from TreeView) at the end of the
existing string (ie just after the "F"), the new string is inserted
just before it (ie between the "E" and the "F"), because the
GetCharIndexFromPosition() function does not return 6 but 5, and so the
insertin is made one char before.
Is this a known bug, or is there a bug in my code ? Thank you for your
help.
Here is the code I use to insert the string dragged from the treeview
on the RTF Text Box :
void richTextBoxMessageContent_DragDrop(object sender, DragEventArgs
e)
{
string newText = (string) e.Data.GetData(typeof
(System.String));
Point pc = richTextBoxMessageContent.PointToClient(new
Point(e.X,e.Y));
var index =
richTextBoxMessageContent.GetCharIndexFromPosition(pc);
var l = richTextBoxMessageContent.TextLength;
richTextBoxMessageContent.Text =
richTextBoxMessageContent.Text.Insert(index, newText);
richTextBoxMessageContent.Focus();
}
I am working on an application including a drag and drop feature
between a TreeView and a RTF Text box. But I have a problem : when
there is already a string in the RTF Text Box ("ABCDEF" for example),
and if I drop the new string (coming from TreeView) at the end of the
existing string (ie just after the "F"), the new string is inserted
just before it (ie between the "E" and the "F"), because the
GetCharIndexFromPosition() function does not return 6 but 5, and so the
insertin is made one char before.
Is this a known bug, or is there a bug in my code ? Thank you for your
help.
Here is the code I use to insert the string dragged from the treeview
on the RTF Text Box :
void richTextBoxMessageContent_DragDrop(object sender, DragEventArgs
e)
{
string newText = (string) e.Data.GetData(typeof
(System.String));
Point pc = richTextBoxMessageContent.PointToClient(new
Point(e.X,e.Y));
var index =
richTextBoxMessageContent.GetCharIndexFromPosition(pc);
var l = richTextBoxMessageContent.TextLength;
richTextBoxMessageContent.Text =
richTextBoxMessageContent.Text.Insert(index, newText);
richTextBoxMessageContent.Focus();
}