Counting lines displayed by richtextbox in C#

北城余情 提交于 2020-01-02 06:21:29

问题


In my project I want to count lines displayed by richtextbox in C# with word wrap property set true. For example, in richtextbox, I write a text, and when text reaches the width of the richtextbox, then it automatically goes to second line. So what happens is the text contains actually one line but it is displayed in two lines. So I want to know how can I count this as two lines instead of one? Help will be really appreciated.


回答1:


You may go for RichTextBox.GetLineFromCharIndex Method

Retrieves the line number from the specified character position within the text of the RichTextBox control. If WordWrap is set to false, no portion of the line wraps to the next, and the method returns 0 for the specified character index.

Also, check out this link.



来源:https://stackoverflow.com/questions/6543906/counting-lines-displayed-by-richtextbox-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!