Windows Form RTF formatting for the RichTextBox Control

寵の児 提交于 2019-12-11 06:16:33

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/4204840/windows-form-rtf-formatting-for-the-richtextbox-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!