winforms - How to find the position of a single word of text in a form C# -
i'm not sure if possible or not. i'm interested in being able find (x,y) position of word of text on winform
.
for example, in picture below, want able pull (x,y) coordinate of upper-left hand corner of letter h in "here".
i know how position of textbox, can make rough estimate based off of word "here" inside textbox, able ask program word if possible.
also, if there way position, i'd able length , height of word (basically want know coordinates of bounding box of word "here" if possible)
not sure if matters, textbox richtextbox
, , textbox populated string array in form1
class.
thank in advance!
you can use getpositionfromcharindex
method, position of "here" within textbox
or richtextbox
(it works both).
as know, position in window have sum position of richtextbox
. this:
int index = richtextbox1.text.indexof("here"); point textboxlocation = richtextbox1.getpositionfromcharindex(index); point windowslocation = new point(richtextbox1.location.x + textboxlocation.x, richtextbox1.location.y + textboxlocation.y); console.writeline("position in textbox: " + textboxlocation.tostring()); console.writeline("position in window: " + windowslocation.tostring());
Comments
Post a Comment