在 System.Windows.Forms.RichTextBox 中存储任意应用程序数据

发布于 2024-09-26 00:54:49 字数 1055 浏览 0 评论 0原文

有谁知道在 RichTextBox 中存储任意数据而用户无法看到这些数据的方法吗? 2007 RTF 规范包括注释(“\atnid”、“\atnauthor”、“\annotation”等),但每当我将这些插入到 RichTextBox.Rtf,注释消失(大概是因为 RichTextBox 不支持 RTF 注释。)我有 有关是否可以将信息存储在图元文件图像内的相关问题。这些解决方案中的任何一个都是可以接受的。 TIA。

我正在尝试的是这样的:

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;

更新:应用程序元数据(“注释”)必须与 RTF 中的特定位置相对应。每个 RichTextBox(或 RTF 文档,如果您愿意的话)也会有多个注释。我还希望元数据与 RTF 一起保留。因此,虽然可以将元数据保存在 control.Tag 中,但我必须自己将信息添加到数据库中,注意用户何时编辑 RTF,并以某种方式确定元数据在编辑后的新位置。编辑。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

又怨 2024-10-03 00:54:49

我认为 atandb 的回应将提供正确的解决方案。您可以使用 \v 和 \v0 隐藏其间的数据,并将隐藏的数据作为特定数据访问到该特定位置。

我在 richtextbox 中尝试过,rtf 属性支持这一点,并且它不会通过跳过控制代码来修改 rtf 内容。我遇到了同样的问题,幸运的是我最终得到了这个页面,现在我可以为 rtf 数据中的任何位置提供一些注释/评论,例如功能。

非常感谢 Carl 的提问和 AtanDB 的回答。

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.

难如初 2024-10-03 00:54:49

我不知道是否有任何特殊的方法可以对 RTF 文档执行此操作,但是如果您只想将一些数据存储在控件(任何类型的 Control)中而不向用户显示,那么您可以使用 Tag 属性,如下所示:Control.Tag

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

难如初 2024-10-03 00:54:49

我认为ho1的想法是正确的。 Control.Tag 是一个对象,因此您可以使用列表、哈希、字典等通用数据结构来存储多个注释并将其存储在 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.

—━☆沉默づ 2024-10-03 00:54:49

富文本控件支持使用 \v 隐藏单词,并使用 \v0 关闭隐藏,不,我没有混淆它们,即使逻辑上 \v 代表可见,但它的作用相反。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文