简单点的,可以这样:
private string demoText = "---[白天非诚勿扰,晚上让子弹飞,结果有了赵氏孤儿!]";
private void GetContent(int line)
{
//StringBuilder sb = new StringBuilder();
string s = string.Empty;
for (int i = 1; i <= line; i++)
{
s = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "-" + "第" + i.ToString() + "次日记" + demoText;
rtbMain.AppendText(s + System.Environment.NewLine);
}
}
private void rtbMain_TextChanged(object sender, EventArgs e)
{
if (rtbMain.Lines.Length > 20)
{
rtbMain.Text = rtbMain.Text.Substring(rtbMain.Lines[0].Length + 1);
}
}
也可以参考这里:
加入的时候就做个累加器(变量),加入前判断过量清楚。