问题
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 tofalse
, 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