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";//改变文本内容 //this.textbox1.text += msg ;//改变文本内容 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(); }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论