C#關(guān)于Textbox滾動顯示最后一行,不閃爍問題
更新時間:2024年04月17日 09:23:41 作者:zgscwxd
這篇文章主要介紹了C#關(guān)于Textbox滾動顯示最后一行,不閃爍問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
C# Textbox滾動顯示最后一行,不閃爍

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";//改變文本內(nèi)容
//this.textBox1.Text += msg ;//改變文本內(nèi)容
this.textBox1.AppendText(msg);//追加文本
this.textBox1.SelectionStart = this.textBox1.Text.Length;
this.textBox1.ScrollToCaret();//滾動到最后一行
}
}
}
}C# textBox多行文本框自動滾動到最后一行
來,看例子吧
/// <summary>
/// textBox多行文本框,自動滾動到最后一行
/// </summary>
/// <param name="msg"></param>
public void add_textbox_msg(string msg)
{
//容錯處理
if (string.IsNullOrEmpty(msg))
{
return;
}
textBox1.AppendText(msg);
textBox1.AppendText("\r\n");//換行
textBox1.ScrollToCaret();
}總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
C# Dictionary和SortedDictionary的簡介
今天小編就為大家分享一篇關(guān)于C# Dictionary和SortedDictionary的簡介,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-10-10

