如何从 Web 应用程序保存富文本并将其显示在富文本框中
我目前正在与一位同事一起开发一个应用程序 - 她正在编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
几年前我就玩过这个——基本上我在数据库中有文本,我正在标记这些文本以强调某些单词。 我在存储过程中对其进行了标记,然后在客户端将其转换为 RTF。
我尝试研究 RTF 规范,但仅仅阅读规范并知道该怎么做有点困难。
我建议打开写字板(开始 -> 运行... -> 写字板),并使用不同的字体样式等。 然后将其另存为 RTF 文档。 在您选择的纯文本编辑器中打开该文档(我使用 Notepad++),这将帮助您更轻松地计算出 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:
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:
如果用户无法在 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...
正如 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.
使用网络浏览器控件并使用您在网络表单中使用的相同编辑器,这样您将来就不会遇到复杂的问题。
您可以在这两个环境中拥有相同的外观和感觉。 如果您需要一些帮助来使用网络形式的编辑器,请回复此消息。
华泰
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
创建一个名为 temp 的文件夹,然后使用此代码
Create a folder called temp and then use this code