子线程调用窗体控件

        public delegate void OutDelegate(string text);
public void OutText(string text)
{
if (listBox1.InvokeRequired)
{
OutDelegate outdelegate = new OutDelegate(OutText);
this.BeginInvoke(outdelegate, new object[] { text });
return;
}

listBox1.Items.Add(DateTime.Now.ToString() + "" + text);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
}

把listBox1换成你需要的控件,把方法放在你的窗体cs上,子线程直接调用OutText方法即可

posted @ 2011-12-15 10:43  bule  阅读(371)  评论(0编辑  收藏  举报