Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RichTextBox Number of Lines 1

Status
Not open for further replies.

javijerome

Programmer
Jun 26, 2010
25
PH
Hi, name is jerome. i'm a beginner is Visual C# 2008. i have a richtextbox in my form and i want to get the number of lines that was used when the user typed some sentences in the richtextbox area. what codes or RTB property should be placed in the Number_of_lines button class, in order that when the button is click, it show the number of lines through a message box.
 
Code:
MessageBox.Show(string.Format("Number of lines: {0}", this.RTB.Lines.LongLength.ToString()));
 
I think this.RTB.Lines.LongLength is the number of lines separated by newline but not by word wrap.
 
thanks for the respond TipGiver. i forgot to say that i also want to get the value as an integer. so that the lines will be placed in a string array. and the number of lines will be used as an index for the string array. how do i get the number of lines in integer value?
 
jslmvl
Yes, the .Lines[] array has the lines seperated by newline. Just checked it.

javijerome
To get the number as Integer (=32bit wide) use instead the .Length property.
Note that the 'RTB.Lines' is an array itself. Maybe you can use it too. The following will show the second line (what is there on the 2nd line). The array as usual is zero based so 1st line is at index 0, 2nd line is at index 1 .... N-th line is at index (N-1)

Code:
MessageBox.Show(this.RTB.Lines[1].ToString());
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top