Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 :
 
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 :
rtf.AddText("*");
string strRtf = Rtf;
strRtf looks like this (A):
 
{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1031
{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n
\\viewkind4\\uc1\\pard\\f0\\fs17
*\\par\r\n}\r\n"

 
after inserting the Info-Group with the item 'nofpages1' strRtf looks like this (B):
 
{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1031
{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n
{\\Info{\\nofpages1}}
\\viewkind4\\uc1\\pard\\f0\\fs17
*\\par\r\n}\r\n"

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 3:33am
fheyn702
v2

1 solution

Rate this: bad
good
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:
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
  Permalink  
Comments
fheyn at 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 at 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)

  Print Answers RSS
0 OriginalGriff 605
1 Maciej Los 319
2 BillWoodruff 184
3 Richard MacCutchan 180
4 Suraj Sahoo | Coding Passion 180
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
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