简体   繁体   English

在TextBox / RichTextBox中获取文本的XY位置

[英]Getting XY location of text within TextBox/RichTextBox

How to get coordinates of certain character within TextBox and/or RichTextBox? 如何获取TextBox和/或RichTextBox中某些字符的坐标?

I will try to explain this through function: 我将尝试通过功能解释这一点:

Point GetXY(int characterIndex) {
    //do some magic
    return new Point(x, y);
}

Idea is to find where selected text is located so Find dialog will not be displayed over this location but moved to side (like Word is doing). 想法是找到所选文本的位置,这样“查找”对话框将不会显示在该位置上方,而是移到侧面(就像Word那样)。

GetPostitionFromCharIndex可能就是您想要的。

您可以通过使用互操作向SendMessage发送EM_POSFROMCHAR消息来完成此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM