private void AddLogText(string text) { if (this.richTextBox1.InvokeRequired) { addLogCallBack stcb = new addLogCallBack(AddLogText); this.Invoke(stcb, new object[] { text }); } else { this.richTextBox1.AppendText(text); if (richTextBox1.Lines.Length > 2000)//超过2000行清空。 { richTextBox1.Clear(); } } }
private void AddWriteLogText(string text)//真正干活的函数 { if (this.richTextBox2.InvokeRequired) { addLogCallBack stcb = new addLogCallBack(AddWriteLogText); this.Invoke(stcb, new object[] { text }); } else { this.richTextBox2.AppendText(text); if (richTextBox2.Lines.Length > 2000)//超过2000行清空。 { richTextBox2.Clear(); } } }
private void AddLogText(string text) { if (this.richTextBox1.InvokeRequired) { addLogCallBack stcb = new addLogCallBack(AddLogText); this.Invoke(stcb, new object[] { text }); } else { lock (richTextBox1) { if (richTextBox1.Lines.Length > 300) { richTextBox1.Clear(); } this.richTextBox1.AppendText(text); //设置光标的位置到文本尾 richTextBox1.Select(richTextBox1.TextLength, 0); //滚动到控件光标处 richTextBox1.ScrollToCaret(); } } }