将richTextBox中的内容写入txt文件发现不换行(解决方法),在richTextBox指定位置插入文字
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内容插入到当前位置