private void setEnabled(Control control, bool state) { // 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 (control.InvokeRequired) { SetEnableCallback d = new SetEnableCallback(setEnabled); if (control != null && !control.IsDisposed) { control.Invoke(d, new object[] { control, state }); } } else { if (control != null && !control.IsDisposed) { control.Enabled = state; } if (control != null && !control.IsDisposed) { control.Refresh(); } } }
//컨트롤의 활성화 여부를 결정하기 위함 private void SetEnable(Control control, bool flag) { if (control.InvokeRequired) { SetEnableCallback d = new SetEnableCallback(SetEnable); this.Invoke(d, new object[] { control, flag }); } else { control.Enabled = flag; } }
/// <summary> /// Set text property of various controls /// </summary> /// <param name="form">The calling form</param> /// <param name="ctrl"></param> /// <param name="state"></param> public static void SetEnable(Form form, Control ctrl, bool state) { if (ctrl.InvokeRequired) { var d = new SetEnableCallback(SetEnable); form.Invoke(d, new object[] { form, ctrl, state }); } else { ctrl.Enabled = state; } }
public static void SetEnable(Control control, bool enable) { if (control.InvokeRequired) { SetEnableCallback callback = new SetEnableCallback(SetEnable); control.BeginInvoke(callback, new object[] { control, enable }); } else { control.Enabled = enable; } }
public static void SetEnable <TObject>(TObject objCtrl, bool enable, Form winf) where TObject : System.Windows.Forms.Control { if (objCtrl.InvokeRequired) { SetEnableCallback d = new SetEnableCallback(SetEnable); if (winf.IsDisposed) { return; } winf.Invoke(d, new object[] { objCtrl, enable, winf }); } else { objCtrl.Enabled = enable; } }
public static void SetEnable <TObject>(TObject objCtrl, bool enable, Control winf) where TObject : Control { if (objCtrl.InvokeRequired) { SetEnableCallback method = new SetEnableCallback(CallCtrlWithThreadSafety.SetEnable <Control>); try { objCtrl.Invoke(method, new object[] { objCtrl, enable, winf }); } catch { try { objCtrl.Enabled = enable; } catch { } } } else { objCtrl.Enabled = enable; } }
public static void SetWaitCursor <TObject>(TObject objCtrl, bool enable, Control winf) where TObject : Control { if (objCtrl.InvokeRequired) { SetEnableCallback method = new SetEnableCallback(CallCtrlWithThreadSafety.SetWaitCursor <Control>); try { objCtrl.Invoke(method, new object[] { objCtrl, enable, winf }); } catch { try { objCtrl.Cursor = !enable ? Cursors.Default : Cursors.WaitCursor; } catch { } } } else { objCtrl.Cursor = !enable ? Cursors.Default : Cursors.WaitCursor; } }
// Method to enable or disable a GUI item, ensure cross-thread support, as Spokes events come in on a different thread // For PictureBox the optional pictureBoxImage allows you to specify a greyed out or normal image! private void SetEnable(Control guiitem, bool enable, Bitmap pictureBoxImage = null) { if (guiitem.InvokeRequired) { SetEnableCallback d = new SetEnableCallback(SetEnable); this.Invoke(d, new object[] { guiitem, enable, pictureBoxImage }); } else { guiitem.Enabled = enable; if (pictureBoxImage != null) { try { PictureBox pbox = (PictureBox)guiitem; pbox.Image = pictureBoxImage; pbox.Update(); } catch (Exception) { } } } }