簡體   English   中英

在Richtextbox中更改線條的顏色

[英]Change the color of a line in Richtextbox

我要第二行,更改為另一種顏色。

我的代碼如下:

 private void WindowLoaded(object sender, RoutedEventArgs e)
    {
        UpdateRTBOnDifferentThread("stackoverflow.com" + Environment.NewLine+"stackoverflow.org" + Environment.NewLine);
    }

    private void UpdateRTBOnDifferentThread(string message)
    {
        Dispatcher.Invoke(DispatcherPriority.Normal, new DispatcherOperationCallback(delegate
        {
            var newExternalParagraph = new Paragraph(new Run(message)) {Foreground = Brushes.Black};
            richTextBox1.Document.Blocks.Add(newExternalParagraph);
            return null;
        }), null);
    } 

第二行是:“ stackoverflow.org”

我要在輸入文字后更改顏色

您可以使用String.Split來中斷UpdateRTBOnDifferentThread方法中的行,也可以使此方法接受字符串數組。 然后,您可以迭代該數組並在同一段落內添加N個Paragraph對象或N個Run對象,並分別控制每個字符串的前景。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM