Is there a way to know/set cursor position on DragOver and DragDrop methods for the FormattedTextEditor?
I'm doing something like a text editor and would like to drag&drop some text but cannot find the way to place it other than the beginning and the end of already written text.
Many thanks
I found a simple way to achieve that instead of coding a DrawFilter: place a label with a black background color on top of the caret that is not blinking when dragging over.
Simply hide the label on DragDrop and DragLeave.
// Get the cursor position related to the window (not the screen) var localPoint = TextEditor.PointToClient(new Point(e.X, e.Y)); // Get the caret position inside the text editor int caretPosition = TextEditor.EditInfo.GetCaretPositionFromMouseLocation(localPoint); // Get the caret location computed from it's position Rectangle rect = TextEditor.EditInfo.GetCaretLocation(caretPosition); // Display a label where on top of the caret lblDropIndicator.Width = 2; lblDropIndicator.Height = rect.Height; lblDropIndicator.Location = rect.Location; lblDropIndicator.Visible = true;
An alternative to this approach is to apply a background colour of SystemColors.Highlight to the selected text, then move the SelectionStart to the mouse position using GetCaretPositionFromMouseLocation, and remove the background colour on MouseUp.