public void SetControl(bool Pro_IsEnabled, bool City_IsEnabled, bool Area_IsEnabled, bool Town_IsEnabled, bool Village_IsEnabled, bool Exception_IsEnabled) { try { if (this.InvokeRequired) //控件是否跨线程?如果是,则执行括号里代码 { if (this.IsDisposed == false || this.IsHandleCreated) { SetControlCallback setControlCallback = new SetControlCallback(SetControl); //实例化委托对象 this.Invoke(setControlCallback, new object[] { Pro_IsEnabled, City_IsEnabled, Area_IsEnabled, Town_IsEnabled, Village_IsEnabled, Exception_IsEnabled }); } } else //否则,即是本线程的控件,控件直接操作 { this.省ToolStripMenuItem.Enabled = Pro_IsEnabled; this.市级ToolStripMenuItem.Enabled = City_IsEnabled; this.区县ToolStripMenuItem.Enabled = Area_IsEnabled; this.镇ToolStripMenuItem.Enabled = Town_IsEnabled; this.村ToolStripMenuItem.Enabled = Village_IsEnabled; this.异常数据处理ToolStripMenuItem.Enabled = Exception_IsEnabled; } } catch { ; } }
private void GUIswitchLEDControllerReady(bool ready) { if (this.grpLEDControl.InvokeRequired) //Falls Invoke benötigt wird (da von anderem Thread aufgerufen)... { SetControlCallback d = new SetControlCallback(GUIswitchLEDControllerReady); this.Invoke(d, new object[] { ready }); } else { this.grpLEDControl.Enabled = ready; //When ready is activiated, when not: deactivated } }
private void setControl(string method, object obj) { if (this.InvokeRequired) { SetControlCallback d = new SetControlCallback(setControl); this.Invoke(d, new object[] { method, obj }); } else { if (method.Equals("startButton_Click")) { startButton_Click(null, null); } else if (method.Equals("stopButton_Click")) { stopButton_Click(null, null); } } }
private void CheckIfSelection() { bool locked = false; SetControlCallback enable = new SetControlCallback(enableAllElements); SetControlCallback disable = new SetControlCallback(lockAllElements); while (_shouldStop) { try { Enroute.drawing = Enroute.enr.ActiveDrawing; Enroute.selection = Enroute.drawing.Selection; if (Enroute.selection != null && Enroute.selection.Count == 0) { this.Invoke(disable); locked = true; //im.Original = true; //im.OrgIamge = null; } else { this.Invoke(enable); locked = false; } Thread.Sleep(1000); } catch { if (!locked) { try { this.Invoke(disable); locked = true; } catch { } } } } }
private void GUIswitchDisConnected(bool connected) { if (this.btnConnect.InvokeRequired) //Falls Invoke benötigt wird (da von anderem Thread aufgerufen)... { SetControlCallback d = new SetControlCallback(GUIswitchDisConnected); this.Invoke(d, new object[] { connected }); } else { if (connected) { this.btnConnect.Enabled = false; this.btnDisconnect.Enabled = true; } else { this.btnConnect.Enabled = true; this.btnDisconnect.Enabled = false; } } }
/// <summary> /// Outputs the specified text. /// </summary> /// <param name="control">The control.</param> /// <param name="menuItem">The menu item.</param> /// <param name="currentControl">The current control.</param> private void SetControl(Control control, TreeMenu menuItem) { if (control.InvokeRequired) { SetControlCallback scc = new SetControlCallback(SetControl); this.Invoke(scc, new object[] { control, menuItem }); } else { //if (currentControl != null) currentControl.Visible = false; if (currentControl != null) { currentControl.Enabled = false; currentControl.Dock = DockStyle.None; } control.Tag = menuItem.Module; control.Enabled = true; control.Dock = DockStyle.Fill; control.BringToFront(); currentControl = control; } }
/// <summary> /// Outputs the specified text. /// </summary> /// <param name="control">The control.</param> /// <param name="menuItem">The menu item.</param> /// <param name="currentControl">The current control.</param> private void SetControl(Control control, TreeMenu menuItem) { if (control.InvokeRequired) { SetControlCallback scc = new SetControlCallback(SetControl); this.Invoke(scc, new object[] { control, menuItem}); } else { //if (currentControl != null) currentControl.Visible = false; if (currentControl != null) { currentControl.Enabled = false; currentControl.Dock = DockStyle.None; } control.Tag = menuItem.Module; control.Enabled = true; control.Dock = DockStyle.Fill; control.BringToFront(); currentControl = control; } }