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

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() + "運(yùn)行】"+"序號(hào): " +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();//滾動(dòng)到最后一行
}
}
}
}C# textBox多行文本框自動(dòng)滾動(dòng)到最后一行
來(lái),看例子吧
/// <summary>
/// textBox多行文本框,自動(dòng)滾動(dòng)到最后一行
/// </summary>
/// <param name="msg"></param>
public void add_textbox_msg(string msg)
{
//容錯(cuò)處理
if (string.IsNullOrEmpty(msg))
{
return;
}
textBox1.AppendText(msg);
textBox1.AppendText("\r\n");//換行
textBox1.ScrollToCaret();
}總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
C# Dictionary和SortedDictionary的簡(jiǎn)介
今天小編就為大家分享一篇關(guān)于C# Dictionary和SortedDictionary的簡(jiǎn)介,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-10-10
C#使用Dispose模式實(shí)現(xiàn)手動(dòng)對(duì)資源的釋放
這篇文章主要介紹了C#使用Dispose模式實(shí)現(xiàn)手動(dòng)對(duì)資源的釋放,涉及C#采用Dispose模式操作資源的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08

