Winforms: Screen Location of Caret Position

2019-02-23 08:42发布

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

2条回答
ゆ 、 Hurt°
2楼-- · 2019-02-23 08:54

You can do it only with native interop: GetCaretPos

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCaretPos(out Point lpPoint);
查看更多
倾城 Initia
3楼-- · 2019-02-23 08:59

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

查看更多
登录 后发表回答