Sunday, April 3, 2011

Winforms: Screen Location of Caret Position

How can I find the screen position of the caret for a standard Winforms TextBox?

From stackoverflow
  • You can do it only with native interop: GetCaretPos

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool GetCaretPos(out Point lpPoint);
    
    bbqfrito : Worked like a charm. Thanks!
  • I have been using the TextBox.GetPositionFromCharIndex function. It gives coordinates relative to the top left of the the TextBox.

0 comments:

Post a Comment