C# 无法计算richtextbox中的行号
这是我的密码C# 无法计算richtextbox中的行号,c#,richtextbox,line,C#,Richtextbox,Line,这是我的密码 private void Allocation_Matrix_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { int Total_Row_Check; Total_Row_Check = getRow(); Textbox1.Text = Convert.ToString(Tota
private void Allocation_Matrix_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
int Total_Row_Check;
Total_Row_Check = getRow();
Textbox1.Text = Convert.ToString(Total_Row_Check);
if (Total_Row_Check >= Convert.ToInt32(Total_Processes.Text))
{
MessageBox.Show("rows cannot exceed from total number of processess");
}
}
}
public int getRow()
{
int Row = 0;
string[] arLines;
int i;
arLines = Allocation_Matrix.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
for (i = 0; i < arLines.Length; i++)
{
Row++;
}
return Row;
}
private void Allocation\u Matrix\u KeyPress(对象发送方,KeyPressEventArgs e)
{
如果(e.KeyChar==13)
{
整数总计行检查;
总计行检查=getRow();
Textbox1.Text=Convert.ToString(总计行检查);
如果(总计行检查>=Convert.ToInt32(总计处理.Text))
{
Show(“行不能超过进程总数”);
}
}
}
public int getRow()
{
int行=0;
字符串[]arline;
int i;
arLines=Allocation_Matrix.Text.Split(新字符串[]{Environment.NewLine},StringSplitOptions.None);
对于(i=0;i
我想更新TextBox1,因为我在键盘上点击了richtextbox中的ENTER键……但Textbox只显示第一行并显示一(1)分配矩阵是您的richtextbox吗 请注意,对于换行符,RichTextBox.Text返回带有换行符(“\n”)的文本,大多数其他Windows控件使用回车符换行符(“\r\n”)
因此,如果您对Text属性返回的字符串调用Split,它将不包含任何Evironment.NewLine。使用方法如何?它返回字符索引所在的从零开始的行号。尝试分配\u Matrix.Text.Lines.Count()方法
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
var lineCount = richTextBox.Lines.Count();
numberLabel.Text = lineCount.ToString();
}
没有这样的方法可用:public int getRows(){string[]arLines;int i;arLines=Allocation_Matrix.Text.Split(新字符串[]{Environment.NewLine},StringSplitOptions.None);for(i=0;i