private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule) { System.Windows.Controls.RichTextBox rtbx = TargetRichTextBox; var tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd); tr.Text = logMessage + "\n"; tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty))) ); tr.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty))) ); tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style); tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight); if (this.MaxLines > 0) { this.lineCount++; if (this.lineCount > MaxLines) { tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd); tr.Text.Remove(0, tr.Text.IndexOf('\n')); this.lineCount--; } } if (this.AutoScroll) { rtbx.ScrollToEnd(); } }
private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule) { System.Windows.Controls.RichTextBox rtbx = TargetRichTextBox; var scrolledToEnd = AutoScroll && (TargetRichTextBox.VerticalOffset + TargetRichTextBox.ViewportHeight) >= (TargetRichTextBox.ExtentHeight - .1); var tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd); tr.Text = logMessage + "\n"; tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty))) ); tr.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty))) ); tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style); tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight); if (MaxLines > 0) { while (rtbx.Document.Blocks.Count - 1 > MaxLines) { rtbx.Document.Blocks.Remove(rtbx.Document.Blocks.FirstBlock); } } if (AutoScroll && scrolledToEnd) { rtbx.ScrollToEnd(); } }
void AppendText(RichTextBox box, Brush color, string text) { TextPointer end = box.Document.ContentEnd; TextRange tr = new TextRange(end, end); tr.Text = text; tr.ApplyPropertyValue(TextElement.ForegroundProperty, color); box.ScrollToEnd(); }
public static void AppendText(System.Windows.Controls.RichTextBox box, string text, SolidColorBrush brush) { TextRange tr = new TextRange(box.Document.ContentEnd, box.Document.ContentEnd); tr.Text = text; tr.ApplyPropertyValue(TextElement.ForegroundProperty, brush); box.ScrollToEnd(); }
//Здесь у обжект будем передавать цвет Brushes.Color!!! public void Log(RichTextBox box1, string msg, object color) { box1.Dispatcher.Invoke(new Action(() => { TextRange range = new TextRange(box1.Document.ContentEnd, box1.Document.ContentEnd); range.Text = msg; range.ApplyPropertyValue(TextElement.ForegroundProperty, color); box1.ScrollToEnd();// функция Autoscroll })); }
//EXTENDED METHODS VVVVVVVVVVVVV public static void Write(this System.Windows.Controls.RichTextBox box, string text, SolidColorBrush color) { Console.WriteLine(text); TextRange tr = new TextRange(box.Document.ContentEnd, box.Document.ContentEnd) { Text = text }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, color); box.ScrollToEnd(); }
public void logWithTime(string s, RichTextBox rtb) { DateTime DTN = DateTime.Now; string LogDateTime = DateTime.SpecifyKind(DTN, DateTimeKind.Local).ToString(); try { rtb.AppendText(LogDateTime + ": " + s + "\r\n"); rtb.ScrollToEnd(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public override void Write(string message) { Action append = delegate() { output.AppendText(string.Format("[{0}] ", DateTime.Now.ToString("T"))); output.AppendText(message); output.ScrollToEnd(); }; if (output.Dispatcher.CheckAccess()) { output.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, append); } else { append(); } }
public void logWithoutTime(string s, RichTextBox rtb) { rtb.AppendText(s + "\r\n"); rtb.ScrollToEnd(); }