GetCaretIndexFromPoint on SqlTextEditor
Hello,
is there any workaround to use GetCharIndexFromPosition and GetPositionFromCharIndex (WinForms Textbox has them) with the SqlTextEditor. I want to move the Caret while Dragging Something Over the SqlTextEditor:
private int GetCaretIndexFromPoint(TextBox box, int x, int y)
{
Point realPoint = box.PointToClient(new Point(x, y));
int index = box.GetCharIndexFromPosition(realPoint);
if (index == box.Text.Length - 1)
{
Point caretPoint = box.GetPositionFromCharIndex(index);
if (realPoint.X > caretPoint.X)
{
index += 1;
}
}
return index;
}
If i change the Parameter from TextBox to ActiveDatabaseSoftware.ExpressionEditor.SqlTextEditor the GetCharIndexFromPosition and GetPositionFromCharIndex are not implemented :(
Any Ideas?
best Regards
Manuel
You should handle the PreProcessDragOver and PreProcessDragDrop events of SqlTextEditor:
private void sqlTextEditor_PreProcessDragOver(object source, DragEventArgs eventArgs, ref bool handled) { if (eventArgs.Data.GetDataPresent(typeof(TreeNode))) { handled = true; eventArgs.Effect = DragDropEffects.Copy; // move the caret int offset = sqlTextEditor.GetOffsetFromPoint(new Point(eventArgs.X, eventArgs.Y)); sqlTextEditor.SetSelection(offset, 0); } } private void sqlTextEditor_PreProcessDragDrop(object source, DragEventArgs eventArgs, ref bool handled) { if (eventArgs.Data.GetDataPresent(typeof(TreeNode))) { handled = true; sqlTextEditor.Focus(); sqlTextEditor.ReplaceSelection(((TreeNode) eventArgs.Data.GetData(typeof(TreeNode))).Text); } }