您的位置:首页 > 编程语言 > C#

C#通过委托处理 控件

2009-11-09 15:17 218 查看
public Form1()

{

InitializeComponent();

listBoxCallback = new AddListBoxItemCallback(AddListBoxItem);

}

// string senddate,readdate;

// NetworkStream ns;

delegate void AddListBoxItemCallback(string text);

AddListBoxItemCallback listBoxCallback;

private void AddListBoxItem(string text)

{

//如果listBoxReceive被不同的线程访问则通过委托处理;

if (listBoxReceive.InvokeRequired)

{

this.Invoke(listBoxCallback, text);

}

else

{

listBoxReceive.Items.Add(text);

listBoxReceive.SelectedIndex = listBoxReceive.Items.Count - 1;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: