Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 如何在C#GUI中计算文本框中的行数_C# 4.0 - Fatal编程技术网

C# 4.0 如何在C#GUI中计算文本框中的行数

C# 4.0 如何在C#GUI中计算文本框中的行数,c#-4.0,C# 4.0,我正在使用VisualStudio2010,希望计算C#文本框中的行数。我试过Textbox.Lines.Count,但它不起作用,因为“Lines”在2010年不再可用。有其他方法吗 尝试使用 var count = Textbox.Lines.Length; 或者试试这个: string[] tmpArray = textBox1.Lines; int count = tmpArray.Length; int first=0; int last=0; 计数=0`在这里输入代码`

我正在使用VisualStudio2010,希望计算C#文本框中的行数。我试过Textbox.Lines.Count,但它不起作用,因为“Lines”在2010年不再可用。有其他方法吗

尝试使用

var count = Textbox.Lines.Length;

或者试试这个:

 string[] tmpArray = textBox1.Lines;
 int count =  tmpArray.Length;
int first=0;
int last=0;
计数=0`在这里输入代码`
last=textBox.GetLastVisibleLineIndex();
计数++;

虽然(首先,正如我提到的,“Textbox.Lines.Length”在visual studio 2010中不再可用,因此我尝试:我没有VS 2010,因此我无法检查此项。请在我的答案中尝试新版本。
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++;
}