如何在新线程启动的类中对 RichTextBox.Text 的改写.............
using System;
using System.Windows.Forms;
namespace frm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
System.Threading.Thread thread1 = new System.Threading.Thread(new System.Threading.ThreadStart(this.threadstart));
thread1.Start();
}
private void threadstart()
{
Common.logView log = new Common.logView();
log.richTextBox1 = this.richTextBox1;
log.editText();
}
}
}
namespace Common
{
public class logView
{
public RichTextBox richTextBox1 = new RichTextBox();
delegate void delegateSetLogTextBox(string text, bool color);
public void editText()
{
this.richTextBox1.Text += "在新线程启动的类中对 RichTextBox.Text 的改写";
}
}
}
上面是我的代码,我知道在线程中操作控件需要用 delegate 托管代码......可是我的是在线程启动的类的中操作控件...我在上面的例子中只启动呢一个线程..实际的程序中应该是1个以上的线程..
delegate void delegateSetTextBox(string text);
private void SetTextBox(string text)
{
if (this.richTextBox1.InvokeRequired)
{
delegateSetTextBox d = new delegateSetTextBox(this.SetTextBox);
this.Invoke(d, new object[] { text });
}
else
{
this.richTextBox1.AppendText(text);
}
}
以上的代码..不知道如何用到我上面的代码中......