views:

594

answers:

4

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.

A: 

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
A: 

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.

Josh
A: 

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

Gokul
A: 

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;
CodeJanitor