开发者

Store arbitrary application data in System.Windows.Forms.RichTextBox

Does anyone know of a way to store arbitrary data in a RichTextBox without the user being able to see this data? The 2007 RTF specification includes annotations ("\atnid", "\atnauthor", "\annotation", etc.) but whenever I insert these into a RichTextBox's .Rtf, the annotations disappear (presumably because the RichTextBox doesn't support RTF annotations.) I have a related question about whether it is possible to store the information inside a Metafile image. Either of these solutions would be acceptable. TIA.

What I'm trying is something like this:

string objectXml = MySerialization.ToXml(object);
string commentRtfFragment = String.Format(@"{{\*\atnid MyApp}}{{\*\atnauthor MyApp}}{{\*\annotation {0}}}", objectXml);

string imageRtf = String.Format(@"{{\rtf1 {{\pict\wmetafile{0}\picw{1}\pich{2}\picwgoal{3}\pichgoal{4} {5}}}{6}}}",
    PixelMappingMode.MM_ANISOTROPIC, picw, pich, picwgoal, pichgoal, imageHex, commentRtfFragment);
richTextBox.SelectedRtf = imageRtf开发者_JAVA百科;

Update: The application metadata ("annotations") must correspond with particular locations in the RTF. There will also be multiple annotations per RichTextBox (or RTF document if you like.) I also want the metadata to persist with the RTF. So while it would be possible to persist the metadata in a control.Tag, then I would have to take care of adding the information to the database myself, noting whenever the user edited the RTF and somehow determine the new location of the metadata after the edit.


I think the response with atandb will provide the right solution. You can use \v and \v0 to hide the data inbetween and access that hidden data as a specific data to that particular location.

I tried in the richtextbox and the rtf property supports that and it does not modify the rtf contents by skipping the control code. I had the same problem and I luckily ended up with this page and now I am able to have some annotation/comments like feature for any location in the rtf data.

Thank you very much Carl for your question and AtanDB for your answer.


I don't know if there's any special way for doing this for RTF documents, but if you just want to store some data in a control (any kind of Control) without showing it to the user, you could use the Tag property as can be seen here: Control.Tag


I think ho1 has the right idea. Control.Tag is an object so you could use a generic data structure like List, Hash, Dictionary, etc. to store your multiple annotations and store that in the Tag property.


The richtext control supports hidden words with \v and turns hidden off with \v0 and no, I have not confused them even though logically \v would stand for visible it does the opposite.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜