Wpf

c#WPFRichTextBoxテキストの色



C Wpf Richtextbox Text Color



public MainWindow() { InitializeComponent() Run run = new Run('This is my text') run.Foreground = new SolidColorBrush(Colors.Red) // My Color Paragraph paragraph = new Paragraph() paragraph.Inlines.Add(run) run = new Run() { Text = 'This itttttyyyyyyyyyy yyyyyyyyyyytttttts my text' , Foreground = new SolidColorBrush(Colors.Blue) } paragraph.Inlines.Add(run) txtLog .Document.Blocks.Add(paragraph) txtLog.UpdateLayout()
// ---------------- wrote a public method better -----------------------
display('PinkPinkPinkPinkPinkPink', Colors.Pink) } void display(string txt, Color color) { Run run = new Run() { Text = txt, Foreground = new SolidColorBrush(color) } Paragraph paragraph = new Paragraph() paragraph.Inlines.Add(run) txtLog.Document.Blocks.Add(paragraph) txtLog.UpdateLayout() }