C#Textbox滚动显示最后一行,不闪烁

C#Textbox滚动显示最后一行,不闪烁_第1张图片

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 AliWorkbenchProgram
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int y = 0;

        private void button1_Click(object sender, EventArgs e)
        {
            showmessage();
        }

        public void showmessage()
        {
            y++;
            string msg= "";
            for (int i=0;i<5000; i++)
            {
               msg = "【第" + y.ToString() + "运行】"+"序号: " +i.ToString() + "\r\n";//改变文本内容
             //this.textBox1.Text += msg  ;//改变文本内容

               this.textBox1.AppendText(msg);//追加文本

               this.textBox1.SelectionStart = this.textBox1.Text.Length;
               this.textBox1.ScrollToCaret();//滚动到最后一行

            }

        }


    }
}

 

 

 

 

 

 

 

你可能感兴趣的:(C#)