Winforms: Screen Location of Caret Position

前端 未结 2 1445
温柔的废话
温柔的废话 2021-01-19 07:45

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

相关标签:
2条回答
  • 2021-01-19 08:17

    I have been using the TextBox.GetPositionFromCharIndex function. It gives coordinates relative to the top left of the the TextBox.

    0 讨论(0)
  • 2021-01-19 08:31

    You can do it only with native interop: GetCaretPos

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool GetCaretPos(out Point lpPoint);
    
    0 讨论(0)
提交回复
热议问题