private void AppendLineToOutput(string text, Color color) { if (OutputTextbox.InvokeRequired) { SetTextColorCallback d = new SetTextColorCallback(AppendLineToOutput); this.Invoke(d, new object[] { text, color }); } else { OutputTextbox.SelectionStart = OutputTextbox.TextLength; OutputTextbox.SelectionLength = 0; OutputTextbox.SelectionColor = color; OutputTextbox.AppendText("[" + System.DateTime.Now.ToString("dd/MM HH:mm:ss") + "] " + text + Environment.NewLine); OutputTextbox.SelectionColor = OutputTextbox.ForeColor; if (!this.ContainsFocus) { OutputTextbox.ScrollToCaret(); } Console.Out.WriteLine("[" + System.DateTime.Now.ToString() + "] " + text); } }
private void SetTextBoxColor(string TextName) { TextEdit textEdit = (TextEdit)Controls.Find(TextName, true)[0]; // 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 (textEdit.InvokeRequired) { SetTextColorCallback d = new SetTextColorCallback(SetTextBoxColor); this.Invoke(d, new object[] { TextName }); } else { textEdit.BackColor = Color.Red; } }
private void setTextColorAndBack(string text, Color color) { if (this.ChkPortResult.InvokeRequired) { SetTextColorCallback d = new SetTextColorCallback(setTextColorAndBack); this.Invoke(d, new object[] { text, color }); } else { this.ChkPortResult.Text = text; this.ChkPortResult.BackColor = color; } }
private void SetTextColor(int no, String text, Color foreColor, Color backColor) { switch (no) { case 0x01: if (this.bt_ScanPort.InvokeRequired) { SetTextColorCallback d = new SetTextColorCallback(SetTextColor); this.Invoke(d, new object[] { no, text, foreColor, backColor }); } else { this.bt_ScanPort.Text = text; this.bt_ScanPort.ForeColor = foreColor; this.bt_ScanPort.BackColor = backColor; } break; case 0x02: if (this.bt_OpenPort.InvokeRequired) { SetTextColorCallback d = new SetTextColorCallback(SetTextColor); this.Invoke(d, new object[] { no, text, foreColor, backColor }); } else { this.bt_OpenPort.Text = text; this.bt_OpenPort.ForeColor = foreColor; this.bt_OpenPort.BackColor = backColor; } break; case 0x03: if (this.bt_ScanPeripheral.InvokeRequired) { SetTextColorCallback d = new SetTextColorCallback(SetTextColor); this.Invoke(d, new object[] { no, text, foreColor, backColor }); } else { this.bt_ScanPeripheral.Text = text; this.bt_ScanPeripheral.ForeColor = foreColor; this.bt_ScanPeripheral.BackColor = backColor; } break; case 0x04: if (this.bt_ConnectPeripheral.InvokeRequired) { SetTextColorCallback d = new SetTextColorCallback(SetTextColor); this.Invoke(d, new object[] { no, text, foreColor, backColor }); } else { this.bt_ConnectPeripheral.Text = text; this.bt_ConnectPeripheral.ForeColor = foreColor; this.bt_ConnectPeripheral.BackColor = backColor; } break; case 0x05: if (this.bt_StartMeasurement.InvokeRequired) { SetTextColorCallback d = new SetTextColorCallback(SetTextColor); this.Invoke(d, new object[] { no, text, foreColor, backColor }); } else { this.bt_StartMeasurement.Text = text; this.bt_StartMeasurement.ForeColor = foreColor; this.bt_StartMeasurement.BackColor = backColor; } break; default: break; } }