日期:2014-05-18 浏览次数:20825 次
private void button1_Click(object sender, EventArgs e) { // 将以前的文本变为黑色 this.richTextBox1.SelectAll(); this.richTextBox1.SelectionColor = Color.Black; int begin = this.richTextBox1.Text.Length - 1; if (begin < 0) begin = 0; // 添加的文本内容 string addToRichtextbox = "add @ " + DateTime.Now.ToString("yyyyMMddHHmmss.fff"); this.richTextBox1.Text += addToRichtextbox + Environment.NewLine; int end = this.richTextBox1.Text.Length - 1; this.richTextBox1.Select(begin, end - begin+1); // 将新加入的文本变为红色 this.richTextBox1.SelectionColor = Color.Red; }