C# richtextbox 自動下拉到最后 方法 & RichTextBox讀取txt中文后出現亂碼


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"));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM