/// <summary> /// Make a control visible or invisible /// </summary> /// <param name="container">The control that contains the control to change</param> /// <param name="control">The control to change</param> /// <param name="val">True to make it visible, false to make it invisible</param> public static void SetControlVisible(Control container, Control control, bool val) { if (container.InvokeRequired) { SetControlVisibleCallback d = SetControlVisible; try { container.Invoke(d, new object[] { container, control, val }); } catch (Exception) { } } else { control.Visible = val; } }
private void SetControlVisible(Boolean flag, Control ctr) { // 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 (ctr.InvokeRequired) { SetControlVisibleCallback d = new SetControlVisibleCallback(SetControlVisible); this.Invoke(d, new object[] { flag, ctr }); } else { ctr.Visible = flag; } }