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格式內容給控件
http://www.cnblogs.com/wuhuacong/archive/2010/07/20/1781378.html
或在讀取文件內容時加上編碼
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"));