Find the x, y point of a string within a text box

后端 未结 3 459
感动是毒
感动是毒 2021-01-26 07:11

Is there a way to return a point for a string within a text box? I found a COM function GetTextExtentPoint that will return the length of a string, but I want to know the point

3条回答
  •  故里飘歌
    2021-01-26 08:15

    First, figure out the index of the first character of the string.

    int index = textBox1.Text.IndexOf(someString);
    

    Then use GetPositionFromCharIndex.

    Point stringPos = textBox1.GetPositionFromCharIndex(index);
    

    (Code not tested, but something like this should work. Of course you will have to deal with the possibility of duplicate occurrences of your string in the textbox.)

提交回复
热议问题