使用 richtextbox 输出程序运行信息

private delegate void Refresh_CallBack(Color color,string text);


        private void ControlsRefresh(Color color, string text)
        {
            if (this.richTextBox1.InvokeRequired)
            {
                Refresh_CallBack d = new Refresh_CallBack(ControlsRefresh);
                this.Invoke(d, new object[] { color, text });
            }
            else 
            {
                lock (richTextBox1)
                {
                    richTextBox1.AppendText(string.Empty);
                    richTextBox1.SelectionColor = color;
                    richTextBox1.AppendText(DateTime.Now.ToString("HH:mm:ss   "));
                    richTextBox1.AppendText(text);

                    richTextBox1.AppendText("\n");
                    //设定光标所在位置 
                    richTextBox1.SelectionStart = richTextBox1.TextLength;
                    //滚动到当前光标处 
                    richTextBox1.ScrollToCaret();
                }
            }
        }

 

posted on 2018-06-21 17:09  陈德洲  阅读(233)  评论(0编辑  收藏  举报

导航