Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,
and a very successfull year to all of you

the current project I'm working on is at the stage of creating a formatted report to
be printed.
I use RichTextBox to build the text and then add the formatting to the corresponding RTF.

which might look like this :

C#
rtf.OnCmd(BOLD); rtf.AddText("*"); rtf.OffCmd(BOLD);


rtf is an instance of CRtbx derived from RichTextBox.
OnCmd(..) adds an rtf on-tag, OffCmd(..) adds an rtf off-tag, AddText does Text.Append("..");

for the last two weeks i've experimented a lot with RTF and
what is working is : add font to fonttable, set font, set font size and
set text to bold, underline and italics.

Now here is what got me stuck for about a week :

I'm unable to add the Info-Group with some Items ({\Info {Itm1}...{ItmN}}

I do :
C#
rtf.AddText("*");
string strRtf = Rtf;

strRtf looks like this (A):

{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1031<br />
	{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n<br />
	\\viewkind4\\uc1\\pard\\f0\\fs17<br />
 	 *\\par\r\n}\r\n"


after inserting the Info-Group with the item 'nofpages1' strRtf looks like this (B):

{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1031<br />
	{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n<br />
	{\\Info{\\nofpages1}}<br />
	\\viewkind4\\uc1\\pard\\f0\\fs17<br />
	 *\\par\r\n}\r\n"

but after
C#
Rtf = strRtf

Rtf hasn't changed and still looks like (A)

what am I doing wrong here ?
so far google was of no help at all

thanks in advance
Posted
v2

1 solution

You are entering very tedious and error-prone work on a pretty much obsolete text format. I don't understand why doing that. In the very beginning, you mention that you only need to create a report. This is much easier, because you would not need to dig into RTF markup directly, but only format the fragments of text using the API through one or another RichTextBox classes.

If, by some weird reason, you really need to bite the bullet, read the reference on all the syntax:
http://msdn.microsoft.com/en-us/library/aa140280%28office.10%29.aspx[^],
http://www.microsoft.com/en-us/download/details.aspx?id=10725[^],
http://interglacial.com/rtf/[^].

But why?

—SA
 
Share this answer
 
Comments
fheyn 9-Jan-13 11:46am    
thanks for the reply, sergey
to be honest, when I started out on this adventure I was thinking the same, but
a) I didn't find anything adequate.
the report is NOT visible and I didn't find anything that lets me format
RTB-text directly.
b) right now I've gone very far, so far that I even think of DLL
c) to me it's something new and it's VERY challenging

later on I'll look into the links you provided

franz
Sergey Alexandrovich Kryukov 9-Jan-13 11:53am    
1) Now you know where to find the complete format description.
2) Just use RichTextBox API, don't dig into format. Why are you asking? if you did not even tell us what is exactly the RichTextBox type. Read the standard MSDN documentation on the class you are using — it's way too simple.
3) Challenging or not, you either do a job or not; it does not change the truth about things. If you are not brave enough, consider simpler problems to work at. :-) But better think well before doing the job.

You have all you need, and as I explain you everything, so you can consider accepting this answer formally (green button) — thanks.

Of course, your follow-up questions are welcome anyway.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900