been playing around with this:
seems to work ok, but wondering if it could be done faster
1 RichTextBox (RTB1)
1 Webbrowser Control (Default Name: Webbrowser1)
1 command btn (cmdCreate)
Paste Colored * Text into the RTB
(*this is designed to change VB code to HTML for display.. so there is other code that colors it correctly first.... it will not pick up bold/font/etc.. just color...)
VB Code:
Dim txtHTML As String 'Convert to HTML Color Private Function GetHTMLColor(lColor As Long) As String Dim sColor As String Dim sR As String Dim sG As String Dim sB As String sColor = Right(String(6, "0") & Hex(lColor), 6) sR = Mid(sColor, 1, 2) sG = Mid(sColor, 3, 2) sB = Mid(sColor, 5, 2) GetHTMLColor = "#" & sB & sG & sR End Function 'Code to convert Private Sub cmdCreate_Click() Dim clr As String RTB1.SelStart = 0 clr = GetHTMLColor(RTB1.SelColor) txtHTML = "<PRE><font face=" & Chr(34) & "courier new" & Chr(34) & " size=2><font color=" & clr & ">" For x = 1 To Len(RTB1.Text) RTB1.SelStart = x If GetHTMLColor(RTB1.SelColor) <> clr And Mid(RTB1.Text, x, 1) <> " " Then clr = GetHTMLColor(RTB1.SelColor) txtHTML = txtHTML & "</font><font color=" & clr & ">" End If Select Case Mid(RTB1.Text, x, 1) Case "<" txtHTML = txtHTML & "<" Case ">" txtHTML = txtHTML & ">" Case "&" txtHTML = txtHTML & "&" Case Else txtHTML = txtHTML & Mid(RTB1.Text, x, 1) End Select Next txtHTML = txtHTML & "</font></font></PRE>" WebBrowser1.Navigate "about:blank" End Sub 'To Display it to the user Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) If (pDisp Is WebBrowser1.Application) Then WebBrowser1.Document.write txtHTML End If End Sub




Reply With Quote