- 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;
- }
- }
C#通过委托处理 控件
最新推荐文章于 2022-08-25 09:57:17 发布