Click here to Skip to main content
12,953,014 members (55,297 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 :

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 :
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 />

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 />

but after
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 9-Jan-13 2:33am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^],[^],[^].

But why?

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

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.


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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100