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