C# richtextbox 自动滚动到最后 光标到最后 自动显示最后一行
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.SelectionStart = richTextBox1.TextLength;
// Scrolls the contents of the control to the current caret position.
richTextBox1.ScrollToCaret(); //Caret意思:脱字标记;插入标记; (^)
}
其他:
rtxt.AppendText(message+"\n");
rtxt.Select(rtxt.Text.Length, 0);
rtxt.ScrollToCaret();
C# RichTextBox读取txt中文后呈现乱码。
操作RichTextBox的机制来生成RTF文档内容,,然后传入RTF格局内容给控件
或在读取文件内容时加上编码
StreamReader sr = new StreamReader(fs, Encoding.Default);
string strline = sr.ReadLine();
StringBuilder sb = new StringBuilder();
while (strline != null)
{
strline = sr.ReadLine();
sb = sb.Append(strline + "\n");
}
sr.Close();
richTextBox1.Text = sb.ToString();
其他回答1:
StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8);//测试告成
其他回答2:
StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
改成 尝尝
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));