c# richTextBox1添加内容并将滚动条滚动到当前焦点处
1. StringBuilder sb = new StringBuilder();
StringBuilder的改变比string快多了
2. sb.Append("\r\n"); //向stringbuilder中添加内容
3.
richTextBox1output.AppendText(sb.ToString());//https://zhidao.baidu.com/question/84734305.html
向winform自带控件richtextbox中最后一行追加内容。
4. richTextBox1output.ScrollToCaret();//将滚动条滚动到当前焦点处
5.sb.Remove(0, sb.Length);//清除stringbuilder中内容
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1output { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1output_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); double[,] matrix=new double[100,10]; for (int i = 0; i < 100; i++) { for (int j = 0; j < 10; j++) { matrix[i, j] = i + j; } } for (int i = 0; i < 100; i++) { for (int j = 0; j < 10; j++) { sb.Append(matrix[i,j]); sb.Append("\t"); } sb.Append("\r\n"); //richEditControl1output.Text = sb.ToString(); //richEditControl1output.ScrollToCaret(0.5f); richTextBox1output.AppendText(sb.ToString());//https://zhidao.baidu.com/question/84734305.html //richTextBox1output.Text += sb.ToString(); richTextBox1output.ScrollToCaret(); sb.Remove(0, sb.Length); } } } }