想要实现发的是选一个物件,textbox中就显示一次他的名字,然后名字与名字之间用”->”连接,可是现在为什么选一个物件a,然后textbox就是重复显示a->a->a->a->a->a->a->a->a->a->a…
for (int i = 0; i < Selection.ItemCount; i++)
{
comp = (IvcComponent)Selection.getItem(i);
for (int a = 0; a < comp.PropertyCount; a++)
{
object name = comp.getProperty("Name");
string propName = comp.getPropertyName(a);
object propValue = comp.getProperty(propName);
BeginInvoke(new myDelegate3(UpdateTextBox3), name);
}
}
public void UpdateTextBox3(String c_String)
{
if (textBox5.Text != "")
{
textBox5.Text += "->" + c_String.ToString();
}
else
{
textBox5.Text = c_String.ToString();
}
}
解决方案
10
你好好看看,你BeginInvoke(new myDelegate3(UpdateTextBox3), name);传的参数是name,但是name通过comp.getProperty(“Name”);赋值的,可是每次for循环你的comp都没有改变,那么获得的name自然也就不会改变了。假如comp是数组的话,你是不是应该用comp[a].getProperty(“Name”)赋值
10
BeginInvoke(new myDelegate3(UpdateTextBox3), name);这个放到循环外