RichTextBox

  • Thread starter Thread starter Jeti [work]
  • Start date Start date
J

Jeti [work]

I have RichTextBox on my form... When I press the 'OK' button, form must
save contents of the RichTextBox on the disk... It wouldnt be a problem
usually, but it is because i need to save it as HTML. All tags must be
generated (fonts, styles, etc)... After that i would need to read HTML
document and put it in the RichTextBox... I'm searching for the solution for
several days now, but with no success...

Any ideas?
 
Jeti,

The easiest way I can think of to do this would be to automate word,
using it to load and to save the contents to disk. It would be able to
read/write both formats. You can then display it in the RichTextBox once
saved to disk in the proper format (you would have to save to disk as RTF in
order to show in the RichTextBox).

Hope this helps.
 
Hi Jeti

If you can afford $34.50, then you could try this:

https://www.regsoft.net/regsoft/vieworderpage.php3?productid=69887

Not used it myself...but I'm sure that there are lots of similar utilities
available at around the same price.

If you can't (!), then one approach you could try would be to use the DHTML
Edit control. When you paste text from an rtf document, then it maintains
most of the formatting.

HTH

Nigel Armstrong
 
I just knocked up a simple sample...

I should have mentioned it's better just to use MSHTML and set it into
editing mode (assuming you have IE5.5 or better on your client machines)...

Then create a form (HtmlEditForm) with both a rich text box and web browser
control on it. Put the following code in, and hook up the events for form
loading and clicking on the form. You'll also need an empty text file called
test.txt in the root of your C: drive...

HTH

Nigel Armstrong


mshtml.IHTMLDocument2 d = null;

private void HtmlEditForm_Click(object sender, System.EventArgs e)
{
this.richTextBox1.SelectAll();
this.richTextBox1.Copy()
axWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_SELECTALL,SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)
axWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PASTE,SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER);
mshtml.IHTMLDocument3 d3 = (mshtml.IHTMLDocument3)d;
MessageBox.Show(d3.documentElement.outerHTML);

}
private void HtmlEditForm_Load(object sender, System.EventArgs e)
{
this.axWebBrowser1.Navigate("file:///c:/test.txt");
d = (mshtml.IHTMLDocument2)this.axWebBrowser1.Document;
d.designMode = "On";

}
 
Form1.cs(114): No overload for method 'ExecWB' takes '2' arguments
Form1.cs(113): No overload for method 'ExecWB' takes '2' arguments
Form1.cs(121): No overload for method 'Navigate' takes '1' arguments
 
Back
Top