日期:2014-05-17 浏览次数:21018 次
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void dgaddlistbox(string text);
public void addlistbox(string text)
{
if (listBox1.InvokeRequired)
{
dgaddlistbox dg = new dgaddlistbox(addlistbox);
listBox1.Invoke(dg, new object[] { text });
}
else
{
if (listBox1.Items.Count > 100) listBox1.Items.RemoveAt(100);
text = DateTime.Now.ToString() + "|" + text;
listBox1.Items.Insert(0, text);
}
}
public class myclass
{
public string text;
public void my()
{
...
...
...
//这个位置要如何才能调用 addlistbox
//调用位置
}
}
private void button1_Click(object sender, EventArgs e)
{
myclass mc = new myclass();
mc.text = "my text";
Thread t = new Thread(new ThreadStart(mc.my));
t.IsBackground = tr