C# winfrom 通过委托插入文本
delegate void ShowMessageDelegate(RichTextBox tb, string msg); /// <summary> /// 委托RichTextBox 添加文本 /// </summary> /// <param name="tb"></param> /// <param name="msg"></param> private void ShowMessage(RichTextBox tb, string msg) { if (tb.InvokeRequired) { //ShowMessageDelegate myDelegate = ShowMessage; //方法1 ShowMessageDelegate myDelegate = new ShowMessageDelegate(ShowMessage); //方法2 tb.Invoke(myDelegate, new object[] { tb, msg }); } else { //tb.Text = tb.Text.Insert(0, msg + "\r\n"); tb.Text += msg + "\r\n"; } }