开发者

Windows Form RTF formatting for the RichTextBox Control

I'm working on a windows form application and I want to have a rich text box display the status of events that are firing based on different objects. I want to be able to format the items as they come into the rtb using the rtf property so that they can be easily distinguished from each other by changing font weight and color.

The format would开发者_高级运维 contain

<b><datetime></b> - <colored text>Event Type</colored text> - <plain text>Event Details</plain text>

I've been doing a lot of research on RTF and it appears to be possible, but getting the formatting down is difficult. From what I can find I need to enter a header with very specific tags for it to work in the first place.

It seems like a lot of hoops to jump through just to get it to work and it would be nice if I could find a site where i could enter text into rtb, format it, and then click a button and get back the rtf that is generated that way I would have a good idea of what I would have to do to get this to work.


In the past, I have used WordPad to get small chuncks of RTF to use in an RichTextBox.

Start > Programs > Accessories > WordPad

So the above text gets you this in rtf

{\rtf1\ansi\ansicpg1252\deff0\deflang6153{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\colortbl ;\red255\green0\blue0;}
{\*\generator Msftedit 5.41.21.2509;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\b\f0\fs22 Datetime\b0  - \cf1 Event Type\cf0  - Event Details\par
}

It is then a matter of tinkering with these codes (or understanding rtf ;-) to get the layout you need to copy into the Rtf property.

Hth

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜