private void SetText(string text) { text = Accessory.FilterZeroChar(text); // 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 (this.textBox_terminal1.InvokeRequired) if (textBox_terminal1.InvokeRequired) { var d = new SetTextCallback1(SetText); BeginInvoke(d, text); } else { textBox_terminal1.SelectionStart = textBox_terminal1.TextLength; textBox_terminal1.SelectedText = text; } }
private void SetText(string text) { text = Accessory.FilterZeroChar(text); // 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 (this.textBox_terminal1.InvokeRequired) if (textBox_terminal.InvokeRequired) { var d = new SetTextCallback1(SetText); BeginInvoke(d, text); } else { var pos = textBox_terminal.SelectionStart; textBox_terminal.AppendText(text); if (textBox_terminal.Lines.Length > _logLinesLimit) { var tmp = new StringBuilder(); for (var i = textBox_terminal.Lines.Length - _logLinesLimit; i < textBox_terminal.Lines.Length; i++) { tmp.Append(textBox_terminal.Lines[i]); tmp.Append("\r\n"); } textBox_terminal.Text = tmp.ToString(); } if (checkBox_autoscroll.Checked) { textBox_terminal.SelectionStart = textBox_terminal.Text.Length; textBox_terminal.ScrollToCaret(); } else { textBox_terminal.SelectionStart = pos; textBox_terminal.ScrollToCaret(); } } }
public bool AddText(string text, byte channel, DateTime logTime, TextFormat textFormat, TimeFormat timeFormat = TimeFormat.Default, DateFormat dateFormat = DateFormat.Default) { if (text == null || text.Length <= 0) { return(true); } var tmpStr = new StringBuilder(); var continueString = false; if (channel != _prevChannel) { _prevChannel = channel; } else if (LineTimeLimit > 0) { var t = (int)logTime.Subtract(_lastEvent).TotalMilliseconds; if (t <= LineTimeLimit) { continueString = true; } _lastEvent = logTime; } if (!continueString) { tmpStr.Append(Environment.NewLine); if (logTime != DateTime.MinValue) { if (dateFormat == DateFormat.Default) { dateFormat = DefaultDateFormat; } if (dateFormat == DateFormat.LongDate) { tmpStr.Append(logTime.ToLongDateString() + " "); } else if (dateFormat == DateFormat.ShortDate) { tmpStr.Append(logTime.ToShortDateString() + " "); } if (timeFormat == TimeFormat.Default) { timeFormat = DefaultTimeFormat; } if (timeFormat == TimeFormat.LongTime) { tmpStr.Append(logTime.ToLongTimeString() + "." + logTime.Millisecond.ToString("D3") + " "); } else if (timeFormat == TimeFormat.ShortTime) { tmpStr.Append(logTime.ToShortTimeString() + " "); } } if (Channels.ContainsKey(channel)) { if (!string.IsNullOrEmpty(Channels[channel])) { tmpStr.Append(Channels[channel] + " "); } } } if (textFormat == TextFormat.Default) { textFormat = DefaultTextFormat; } if (FilterZeroChar) { text = Accessory.FilterZeroChar(text); } if (textFormat == TextFormat.PlainText) { tmpStr.Append(text); } else if (textFormat == TextFormat.Hex) { tmpStr.Append(Accessory.ConvertStringToHex(text)); } else if (textFormat == TextFormat.AutoReplaceHex) { tmpStr.Append(ReplaceUnprintable(text)); } return(AddTextToBuffer(tmpStr.ToString())); }