This is the discussion forum for the HtmlEditor. See also the HtmlEditor home page, where you can download the control, and the Documentation Wiki, a collaborative project for documenting the control.
I was envisioning applying the style to a FormatBlock, i.e., a user would select a block of text and apply a style to it. The solution you're suggesting is more toward a single element, correct?
Well, using the span tags with a text range seems to work okay, except for one thing.
When I try to change a style from another one, I can't get the old span tags to go away. When I call rng.pasteHTML, it doesn't replace the entire text contained in rng.htmlText (where rng is a textrange).
this should remove all of the span tag and its contents, and then you just paste in the new content you want to go in there.
you might need to save the textrange contents and perform some processing with regular expressions etc if you dont want to lose all the content inside.
Hi,
I'm trying to get to grips with the HtmlEdit control for use on an internal business project.
I'd like to define a set stylesheet for the content. I've found the htmleditor.setstylesheet method, but this doesn't seem to inject the required reference to the html? (Perhaps as I'm referencing a url rather than a local file system file?)
I've also tried this:
Dim sSheets As onlyconnect.IHTMLStyleSheetsCollection
sSheets = Me.heEmail.HtmlDocument2.GetStyleSheets()
If sSheets.length = 0 Then
Me.heEmail.HtmlDocument2.CreateStyleSheet(My.Resources.WebPath + My.Resources.HTMLMsgStyleSheet, 0)
End If
Where the webpath and HTMLMsgStyleSheet combine to form a full url (the html being created will eventually be sent as an HTML email to customers, so this path is publicly accessible).
But this techique fails with an "object reference not set" type of error - but I'm not sure why the reference isn't created, as I'm trying the code immediately after having loaded an existing html source string to the editor via LoadDocument.
Sorry if this is a bit long-winded.
Appreciate any help offered!
Al
Replying to my own post:
I didn't use the available properties in the end, but a simpler approach of string detection and replacement. This suits my purpose as I'm always going to use the same style sheet reference (the user won't be getting an option to choose).
My method:
Dim source As String = Me.heEmail.GetDocumentSource
'Construct string to look for/insert.
Dim sSheet As String = "<link href=""" & My.Resources.WebPath + My.Resources.HTMLMsgStyleSheet & _
""" rel=""stylesheet"" type=""text/css"" media=""screen"" />"
'Check it doesn't already have our stylesheet
If InStr(source, sSheet) = 0 Then
'Match not found, so we add it.
If source.Contains("</head>") Then
source = source.Replace("</HEAD>", Chr(13) + sSheet + "</head>")
End If
End If
If there's a better method, I'd be glad to improve it!