简体   繁体   中英

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;

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.

我不知道是否对RTF文档有任何特殊的方法,但是如果您只想在控件中存储某些数据(任何类型的Control )而不显示给用户,则可以使用Tag属性在这里看到: 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.

Richtext控件支持带有\\ v的隐藏单词,并带有\\ v0的隐藏单词,并且不,即使逻辑上\\ v代表可见,我也没有混淆它们,相反。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM