string pathname = dt.ToString().Replace(":", "");
string str = richTextBoxResult.Text;
str = str.Replace("\n", "\r\n"); //关键
File.AppendAllText(@"D:\" + pathname + ".txt", str, Encoding.Default); //将文字附加在原有的text文件末尾
private void IndividualMessage_TextChanged(object sender, EventArgs e) //光标随输入移动
{
this.IndividualMessage.SelectionStart = ShowMessage.TextLength;
this.IndividualMessage.ScrollToCaret();
//richTextBox1.Focus(); //此方法不如上边的好
//richTextBox1.Select(richTextBox1.Text.Length, 0);
//richTextBox1.ScrollToCaret();
}
在光标处插入内容:
int startIndex = FileData.SelectionStart; //获取richTextBox控件光标位置
FileData.Text = FileData.Text.Insert(startIndex, content);//将content内容插入到当前位置
时间: 2024-10-21 08:51:32