public void setControl(vm_control ct) { if (this.frm.InvokeRequired) { SetControlCAllback stc = new SetControlCAllback(setControl); frm.Invoke(stc, new object[] { ct }); } else { bool Fnd = false; vm_control pnl = null; for(int i=0;i< frm.UI_VM_CONTAINER.Controls.Count;i++) //foreach (System.Windows.Forms.Control pnl in frm.UI_VM_CONTAINER.Controls) //search between elements in container { if (frm.UI_VM_CONTAINER.Controls[i] is vm_control) { pnl = (vm_control)frm.UI_VM_CONTAINER.Controls[i]; if (ct.lblName.Text == ((vm_control)pnl).lblName.Text) { ((vm_control)pnl).lblName.Text = ct.lblName.Text; ((vm_control)pnl).lblDescription.Text = ct.lblDescription.Text; ((vm_control)pnl).lblOS.Text = ct.lblOS.Text; ((vm_control)pnl).lblProcessorLoad.Text = ct.lblProcessorLoad.Text; ((vm_control)pnl).lblState.Text = ct.lblState.Text; ((vm_control)pnl).imgVM.Image = ct.imgVM.Image; Fnd = true; } } } if (!Fnd) { if (frm.imgWait.Visible == true) frm.imgWait.Dispose(); frm.UI_VM_CONTAINER.Controls.Add(ct); } } }