public static void AddControl(Control parent, Control child) { if (parent.InvokeRequired) { AddControlCallback callback = new AddControlCallback(AddControl); parent.BeginInvoke(callback, new object[] { parent, child }); } else { parent.Controls.Add(child); } }
public void AddControl(Control p_oParentControl, Control p_oChildControl) { if (p_oParentControl.InvokeRequired) { AddControlCallback d = new AddControlCallback(AddControl); p_oParentControl.Invoke( d, new object[] { p_oParentControl, p_oChildControl }); } else { p_oParentControl.Controls.Add(p_oChildControl); } }
public MapViewModel(AddControlCallback handler) { addControllCallback += handler; }
private void AddControl(Control ctr1, Control ctr2) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (ctr1.InvokeRequired) { AddControlCallback d = new AddControlCallback(AddControl); this.Invoke(d, new object[] { ctr1, ctr2 }); } else { ctr1.Controls.Add(ctr2); } }