Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WebBrowser, Styles, and DesignMode

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
US
Hello all.

I'm creating a C# CMS for our website, and I'm trying to incorporate a WYSWIG HTML editor for a couple of screens.

I'm running into a difficulty with styles though.

In the DocumentCompleted event I am adding styles like this:
Code:
IHTMLStyleSheet sheet = doc.createStyleSheet("", 0);
sheet.addRule("body", "font-family: Calibri, Tahoma, Verdana, Helvetica, Arial;", -1);
...

As long as I don't set designMode to "On", the styles work and what is loaded appears with the styles I specified. Once I set designMode to "On", the styles are lost.

I found some documentation that seems to indicate that setting designMode to "On" reloads the contents - I figured this might be clearing the styles I set. So I set designMode to "On" before creating the styles, and as soon as it tries to create the stylesheet I get an error: "Error HRESULT E_FAIL has been returned from a call to a COM component."

Anyone have any clues on how to handle this?

Thanks.
 
Ok, I think I got this working.

Instead of using:

Code:
doc.designMode = [COLOR=#A31515]"On"[/color]; [green]//An IHTMLDocument2 reference[/green]

I am now using:

Code:
wb.Document.Body.SetAttribute([COLOR=#A31515]"contenteditable"[/color], [COLOR=#A31515]"true"[/color]); [green]//wb is the WebBrowser reference[/green]

Styles are now staying set, and I can edit the page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top