Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
300
FormattedTextEditor drop cursor position
posted

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

Parents
  • 495
    Suggested Answer
    posted

    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;
Reply Children
No Data