c# - How can I get position of text that is shifted down in a RichTextBox due to larger text on the same line? -
there point using getpositionfromcharindex()
location of start of particular string in richtextbox
. due other requirements, made change increase font size of words. if word happens enlarged (and string position want remains same), string i'm measuring gets pushed down y position reads being same reason.
i wrote quick test app verify , can replicate it. below of code using (apart designer of course).
public form1() { initializecomponent(); richtextbox1.text = "test statement"; //select "test" , increase size richtextbox1.selectionstart = richtextbox1.text.indexof("test"); richtextbox1.selectionlength = 4; richtextbox1.selectionfont = new font(richtextbox1.font.fontfamily, 16); point test = richtextbox1.getpositionfromcharindex(richtextbox1.text.indexof("test")); point statement = richtextbox1.getpositionfromcharindex(richtextbox1.text.indexof("statement")); //"statement" pushed down due "test" being enlarged, //yet y value same both words label1.text = $"test location: {test.x},{test.y}"; label2.text = $"statement location: {statement.x},{statement.y}"; }
is can around? word "statement" doesn't truly have same y value. seems far richtextbox
concerned, word start high measures that, if case, there doesn't seem obvious solution me.
getpositionfromcharindex
working as designed.
the docs state:
this method enables determine in control specific character index located. can use method such tasks displaying shortcut menu items or information word in control. example, if wanted display menu of options user when user right clicks on word in control, can use method determine position of word display contextmenu control.
given that, makes sense both words return same y value - since expect right-click act consistently both words (so if right click above statement word still work expected).
Comments
Post a Comment