textBox显示规定行数(更新中的)一段小代码
private void setLogMessage(String strLog)
{
// txtMsg.Text=(txtMsg.TextLength>100000)?"":txtMsg.Text;
// txtMsg.AppendText(System.DateTime.Now.ToString() + " " + strLog +"\r\n");
stringLength=0;
sB.Append( System.DateTime.Now.ToString() + " " + strLog +"\r\n");//保存日志信息的临时字符串
// txtMsg.Text=sB.ToString();
if(txtMsg.Lines.Length>23)//大于23行开始删除第一行
{
tempString=sB.ToString();
for(int i=0;i<sB.ToString().Length-1;i++)
{
if(tempString.Substring(i,2)=="\r\n")//判断出第一个回车时记录字符个数并推出循环
{
stringLength=i+1;
break;
}
}
if(stringLength>0)
{
sB.Remove(0,stringLength); //删除第一行
}
txtMsg.Text=sB.ToString();
}
}
{
// txtMsg.Text=(txtMsg.TextLength>100000)?"":txtMsg.Text;
// txtMsg.AppendText(System.DateTime.Now.ToString() + " " + strLog +"\r\n");
stringLength=0;
sB.Append( System.DateTime.Now.ToString() + " " + strLog +"\r\n");//保存日志信息的临时字符串
// txtMsg.Text=sB.ToString();
if(txtMsg.Lines.Length>23)//大于23行开始删除第一行
{
tempString=sB.ToString();
for(int i=0;i<sB.ToString().Length-1;i++)
{
if(tempString.Substring(i,2)=="\r\n")//判断出第一个回车时记录字符个数并推出循环
{
stringLength=i+1;
break;
}
}
if(stringLength>0)
{
sB.Remove(0,stringLength); //删除第一行
}
txtMsg.Text=sB.ToString();
}
}
posted on 2005-11-25 11:03 Chandler.C 阅读(420) 评论(0) 收藏 举报
浙公网安备 33010602011771号