您的位置:首页 > 其它

可在多线程下TextBox中显示信息,和控制滚动的一个函数

2005-09-21 16:41 239 查看
一、可在多线程下调用显示信息。
二、可以滚动到添加的最后一行。
三、不添加新行,仅在最后一行动态显示动容。
变量messageBox的类型是TextBox

1 private void showMsg(string msg, bool needScroll)
2 {
3 if (this.InvokeRequired == true)
4 {
5 ShowMsgDelegate smd = new ShowMsgDelegate(showMsg);
6 this.Invoke(smd, msg, needScroll);
7 }
8 else
9 {
10 if (needScroll == true)
11 {
12 messageBox.AppendText(msg + "\r\n");
13 messageBox.SelectionStart = messageBox.Text.Length;
14 }
15 else
16 {
17 int li = messageBox.Text.LastIndexOf("\r\n") + "\r\n".Length;
18 messageBox.SelectionStart = li;
19 messageBox.SelectionLength = messageBox.Text.Length - li;
20 messageBox.SelectedText = msg;
21 }
22 }
23 Application.DoEvents();
24 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐