Comments in a RichTextBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to include a comment in an rtf file and save it through vb.net. My problem is that the comment will not save. Details follow

I referenced http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtfspec/html/rtfspec.as
to find a way to add a comment in an RTF file. Below is an rtf file with a comment

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}
\viewkind4\uc1\pard\f0\fs20 This is text\pa
{\*\annotation How about some examples that deal with social science?
That's what this paper is about.}

When I load the file into an rft control, it works fine. I see the text and the comment is hidden. The problem is that when I save the file without any changes, the comment is lost. My load and save code are

Me.rtfDocumentation.LoadFile("c:\TestDoc.rtf"
Me.rtfDocumentation.SaveFile("c:\Testdoc.rtf"

Can I solve this problem by either changing the comment in the file or the command used to save the file?
 
Unfortunately, the RichTextBox tends to strip out RTF codes that it doesn't
support. You can see this simply by importing an RTF file created by
Microsoft Word (which will be very verbose with RTF codes) and then export
the RTF text -- the new file will be much smaller.

I don't know of any way around this. You might have better luck if you
create a RichEdit COM control directly using API functions, but that's a
non-trivial solution. Another possibility would be to get the handle of the
RichEdit control being hosted by the RichTextBox, and use an API function to
set the RichEdit control's rich text property directly (bypassing the
RichTextBox.)

There's an example of using COM interop with a RichEdit control here:
http://msdn.microsoft.com/vbasic/us...ary/en-us/dnwinforms/html/wnf_richtextbox.asp

If there's an easier solution, I'd love to know.



genojoe said:
I want to include a comment in an rtf file and save it through vb.net. My
problem is that the comment will not save. Details follow.
I referenced http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtfspec/html/rtfspec.asp
to find a way to add a comment in an RTF file. Below is an rtf file with a comment:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
\viewkind4\uc1\pard\f0\fs20 This is text\par
{\*\annotation How about some examples that deal with social science?
That's what this paper is about.}}

When I load the file into an rft control, it works fine. I see the text
and the comment is hidden. The problem is that when I save the file without
any changes, the comment is lost. My load and save code are:
Me.rtfDocumentation.LoadFile("c:\TestDoc.rtf")
Me.rtfDocumentation.SaveFile("c:\Testdoc.rtf")

Can I solve this problem by either changing the comment in the file or the
command used to save the file?
 
Back
Top