2017-04-14 59 views

回答

1

尝试使用

var count = Textbox.Lines.Length; 

More detail here

或者试试这个:

string[] tmpArray = textBox1.Lines; 
int count = tmpArray.Length; 
+0

以及我提到的 “Textbox.Lines.Length” 没有在Visual Studio 2010的详细avalable因此我试过: – Goyal

+0

我没有VS 2010,所以我无法检查这个。在我的答案中尝试新版本。 – FetFrumos

0
int first = 0; 
int last = 0; 
count=0;`enter code here` 
last = textBox.GetLastVisibleLineIndex(); 
count++; 
while (first <= last) 
{ 
String dummy = textBox.GetLineText(first); 
if (dummy.Contains("\n") || dummy.Contains("\r") || dummy.Contains("\r\n")) 
{ 
dummy = dummy.TrimEnd('\r', '\n'); 
count++; 
} 
first++; 
}