开发者

How do I change the appearance of some text in a textBox?

I'm building a program similar to Messenger, sort of a chatting software.

I created a textBox to display the conversation log, and I want to make it look like this:

Nick1: Hi.

Nick2: Hello.

开发者_运维知识库

How do I make part of the text bold? I also want to allow users to change their own font, font-color and so on...

Thanks in advance.


Use RichTextBox if building a Windows Forms or a WPF app.


The best way is to use a RichTextEdit control, this control can take RTF format codes to easily format the text the way you want it.

eg.

\pard\plain\ltrpar\f0\fs14\sl240\slmult1\b\ Nick1.\par
\pard\plain\ltrpar\f0\fs14\sl240\slmult1\Hi

will show up as Nick1 Hi


Assuming you're using WPF I'd use an ItemsControl to display the conversion. Then for each item I'd have a couple of TextBlocks one for the user name (which would be bold) and the other for the message.

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜