繁体   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