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"));
posted @ 2018-02-22 16:14  po-A  阅读(1951)  评论(0编辑  收藏  举报

Tushare大数据开放社区-免费提供各类金融数据和区块链数据 , 助力智能投资与创新型投资。

Python, Matlab, R, Web数据抽取学习交流。