这样写就可以了this.comboBox1.Invoke(new Action(() => this.comboBox1.Items.Clear()));
解决方案 »
- 如何对表中的一条记录进行锁定,它用户无法进行修改,但允许自己更新。适当的时候还要进行解锁
- 求高手:WPF窗体中加载ActiveX控件总是显示在最前的问题!!!!!
- 修改注册表中的值
- c#中如何读取一个系统数据(如:系统的进程getallprocess)然后通过button点击控件给显示?
- 怎么让CheckBoxList读取数据库的值
- 可不可以这样调用阿
- 有关委托或事件之 界面之间传值
- 菜鸟问题:我的.exe文件为何不能运行?
- 哪有c# 安裝下載
- 终于可以下载Windows.Net RC1了!!!
- 求助,两个int数组之间的运算
- WPF中执行存储的结果是5个Table,每个Table一列,现在想把5个table分别绑定到5个Combox中,Binding怎么写怎样比较灵活
private void RunWithInvoke()
{
this.progressBar.Invoke(new Action(() =>
{
while (this.progressBar.Value < progressBar.Maximum)
{
this.progressBar.Value++;
//这句是干嘛用的,progressBar的值变化,comboBox1的项就清空?
this.comboBox1.Invoke(new Action(() => this.comboBox1.Items.Clear()));
Console.WriteLine(progressBar.Value.ToString());
}
}));
}
补加一个问题,假如要在
if (InvokeRequired)
{
//this.toolTip1.SetToolTip(comboBox1, "king");
}
中执行被注释的这行语句,该如何编写编码?this.toolTip1没有提供invoke()方法啊?
private void BindMethod()
{
this.toolTip1.SetToolTip(this.comboBox1, "");
} //调用
Thread th = new Thread(new ThreadStart(() =>
{
Bind bind = new Bind(BindMethod);
this.Invoke(bind);
}));
th.Start();
哦,谢谢,还有最后一个问题:
this.comboBox1.Invoke(new Action(() => this.comboBox1.Items.Clear()));
this.Invoke(new Action(() => this.comboBox1.Items.Clear()));这两行编码达到的效果是一样的,那它们有本质上的区别么?或者说编码时这两行编码随便选择之中一个都行!?
1、this.comboBox1指窗体上的comboBox1对象
2、this指窗体对象建议用第一种写法