如何从 Web 应用程序保存富文本并将其显示在富文本框中

发布于 2024-07-23 11:07:55 字数 340 浏览 9 评论 0原文

我目前正在与一位同事一起开发一个应用程序 - 她正在编写一个 Web 表单,允许用户输入和管理文本,这些文本将保存到数据库中,然后显示在桌面应用程序中。

我正在使用富文本框来显示数据库中的文本。 我们希望允许用户在 Web 应用程序中使用基本格式(粗体、斜体、下划线),然后在桌面应用程序中显示该格式。

我想知道是否有一个标签或其他内容可以输入到网络表单中(例如 或 [b] 等),它会自动显示 RTB 中的格式。

如果不可能,实现此功能的最佳方法是什么?

我正在使用 C# Windows 窗体作为桌面应用程序。

更新: Web 表单采用 PHP 语言。

I'm working on an application with a co-worker at the moment - she is writing a web form that allows users to enter and manage text that will be saved to the database and then displayed within a desktop application.

I'm using a Rich Text Box to display the text from the database. We want to allow the users to use basic formatting (bold, italic, underline) in the web app, and then display that formatting in the desktop app.

I'm wondering if there is a tag or something that can be entered into the web form (like or [b] etc), that will automatically display the formatting within the RTB.

If that isn't possible, what will be the best way to achieve this functionality?

I'm using C# windows form for the desktop application.

Update:
The web form is in PHP.

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

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

发布评论

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

评论(5

滥情稳全场 2024-07-30 11:07:55

几年前我就玩过这个——基本上我在数据库中有文本,我正在标记这些文本以强调某些单词。 我在存储过程中对其进行了标记,然后在客户端将其转换为 RTF。

我尝试研究 RTF 规范,但仅仅阅读规范并知道该怎么做有点困难。

我建议打开写字板(开始 -> 运行... -> 写字板),并使用不同的字体样式等。 然后将其另存为 RTF 文档。 在您选择的纯文本编辑器中打开该文档(我使用 Notepad++),这将帮助您更轻松地计算出 RTF。

下面是我创建的一个简单 RTF 文档的示例:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\f0\fs20 Hello World.\par
\b This text is bold.\b0\par
\i This text is italicized.\i0\par
\cf1 This text is blue.\cf0\par
}

其中一些标签只是额外的标记,您可能不需要它们。 尝试一下并看看。

最终你应该能够做一些类似的事情:

string rtf = GetMarkupTextFromServer();
rtf = rtf.Replace("[b]", @"\b");
rtf = rtf.Replace("[/b]", @"\b0");
rtf = rtf.Replace("[i]", @"\i");
rtf = rtf.Replace("[/i]", @"\i0");
    ...
mRichTextBox.Rtf  = rtf;

I played around with this a few years back - basically I had text in a database that I was marking up to emphasize certain words. I marked it up in a stored procedure, and then translated that to RTF on the client side.

I tried looking into the RTF spec, but it's somewhat challenging to just read the spec and know what to do.

I suggest popping open Wordpad (Start -> Run... -> wordpad), and mess around with different font styles and such. Then save it off as an RTF document somewhere. Open up that document in a plain-text editor of your choice (I use Notepad++), and that'll help you figure out RTF a lot easier.

Here's an example of a simple RTF document I created:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\f0\fs20 Hello World.\par
\b This text is bold.\b0\par
\i This text is italicized.\i0\par
\cf1 This text is blue.\cf0\par
}

Some of those tags are just extra markup that you can probably do without. Play around with it and see.

Eventually you should be able to do something along the lines of:

string rtf = GetMarkupTextFromServer();
rtf = rtf.Replace("[b]", @"\b");
rtf = rtf.Replace("[/b]", @"\b0");
rtf = rtf.Replace("[i]", @"\i");
rtf = rtf.Replace("[/i]", @"\i0");
    ...
mRichTextBox.Rtf  = rtf;
英雄似剑 2024-07-30 11:07:55

如果用户无法在 Windows 端编辑数据,而只能在 Web 端编辑数据,您可以将 HTML 源存储在数据库中,并将其显示在 Windows 应用程序的 Web 浏览器控件中...

If the user won't be able to edit the data on the Windows side but only on the web side, you can store the HTML source in the DB and display that in a Webbrowser control in your windows app...

挥剑断情 2024-07-30 11:07:55

正如 BFree 提到的,您在 Web 环境中要做的最好的事情就是富文本 HTML 编辑器。 幸运的是,有许多那里有免费的编辑器。 如果您将信息以 HTML 形式存储在数据库中并选择在 WebForm 中重复使用该信息,那么您将不得不使用 Web 浏览器控件。 但是,您可以选择通过使用库在 HTML 和 RTF 之间来回转换该信息。

不幸的是,经过一番搜索,我找不到任何不需要付费的东西。 您也许可以利用 MS Word 作为数据泵以编程方式进行转换,但这可能无法很好地扩展。

Just as BFree mentioned, the best you are going to do in the web environment is a Rich Text HTML editor. Luckily for you there are numerous free editors out there. If you store the information as HTML in the database and choose to re-use that in a WebForm, you are stuck with a Web Browser control. However, you could choose to convert that information back and forth between HTML and RTF through the use of a library.

Unfortunately, after some searching, I was unable to find any that you don't have to pay for. You might be able to utilize MS Word as a data pump to do the conversion programatically, but this may not scale well.

只为一人 2024-07-30 11:07:55

使用网络浏览器控件并使用您在网络表单中使用的相同编辑器,这样您将来就不会遇到复杂的问题。

您可以在这两个环境中拥有相同的外观和感觉。 如果您需要一些帮助来使用网络形式的编辑器,请回复此消息。

华泰

Use the web-browser control and use the same editor you are using in your webform so that you dont end up with complex issues in future.

You can have the same look and feel on both the environments. If you need some help to use the editor in web-form, please reply to this message.

HTH

自由如风 2024-07-30 11:07:55

创建一个名为 temp 的文件夹,然后使用此代码

frmEditPro.RichTextBox1.SaveFile("C:\temp\Doc1.rtf", _RichTextBoxStreamType.RichText)

Create a folder called temp and then use this code

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