WPF RichTextBox-追加彩色文本 [英] WPF RichTextBox - Appending Colored text

查看:89
本文介绍了WPF RichTextBox-追加彩色文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要将文本附加到WPF RichTextBox,但是要使用特定的颜色.

经过大量的搜索,我将以下方法组合在一起

Hey guys

I need to append text to a WPF RichTextBox, but specific colors.

After much googling i put together the following method

private void AppendRtfText(string Text, Brush Color)<br />{<br />    TextRange range = new TextRange(txtChat.Document.ContentEnd, txtChat.Document.ContentEnd);<br />    range.Text = Text;<br />    range.ApplyPropertyValue(TextElement.ForegroundProperty, Color);<br />}



现在这可以正常工作,但是我需要能够指定RGB值.

TextElement.ForegroundProperty仅接受Brush ,据我所知,我无法为RGB指定像我使用Color 类的画笔.

有什么想法吗?原因我用完了



Now this works just fine, but I need to be able to specify RGB values.

The TextElement.ForegroundProperty only accepts a Brush and as far as I can see I cant specify RGB for a brush like i would with the Color class.

Any ideas? Cause I''m running out

推荐答案

来自 ^ ]

Taken from http://msdn.microsoft.com/en-us/library/system.windows.media.brushes(VS.85).aspx[^]

<br />SolidColorBrush mySolidColorBrush = new SolidColorBrush();<br /><br />// Describes the brush''s color using RGB values. <br />// Each value has a range of 0-255.<br />mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255);<br />




hth,Philipp




hth, Philipp


这篇关于WPF RichTextBox-追加彩色文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆