【WinForm】 RichTextBox使用汇总

1、文本动态滚动显示文本

https://blog.csdn.net/chulijun3107/article/details/79698020

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace RichTextBoxScroll
{
    public partial class Form1 : Form
    {
        private delegate void delInfoList(string text);
        public Form1()
        {
            InitializeComponent();
        }
        
        private void SetrichTextBox(string value)
        {
 
            if (richTextBox1.InvokeRequired)//其它线程调用
            {
                delInfoList d = new delInfoList(SetrichTextBox);
                richTextBox1.Invoke(d, value);
            }
            else//本线程调用
            {
                if (richTextBox1.Lines.Length > 100)
                { 
                    richTextBox1.Clear();
                }
 
                richTextBox1.Focus(); //让文本框获取焦点 
                richTextBox1.Select(richTextBox1.TextLength, 0);//设置光标的位置到文本尾
                richTextBox1.ScrollToCaret();//滚动到控件光标处 
                richTextBox1.AppendText(value);//添加内容
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 300; i++)
            {
                SetrichTextBox(DateTime.Now.ToString() + " 内容滚动打印中!!!
");
            } 
        }
    }
}

2、让richtextbox水平滚动条出现
将控件wordwrap属性设置为false

/*******相与枕藉乎舟中,不知东方之既白*******/
原文地址:https://www.cnblogs.com/Mars-0603/p/13597201.html