Measure String inside RichTextBox Control

后端 未结 6 1012
刺人心
刺人心 2020-12-19 02:44

Can somebody please explain how I would go about measuring the string inside a richtextbox control so that the I can automatically resize the richtextbox control according t

6条回答
  •  春和景丽
    2020-12-19 03:05

    You can measure a string by calling TextRenderer.MeasureText.

    However, if the text contains multiple fonts, this will not work.

    EDIT: You're looking for the GetPositionFromCharIndex method.
    Note that if there are multiple lines, you should take the max of the X coordinates of the last character on each line.

提交回复
热议问题