logixologist
logixologist

Reputation: 3834

Rich Text in a VB6 text box

Does anyone know if there is a way outside of using a 3rd Party text box control, to enter HTML into a VB6 text box.

I havent found anything online.

Upvotes: 0

Views: 2478

Answers (1)

Kevin O'Donovan
Kevin O'Donovan

Reputation: 1669

Hopefully you'll be able to make use of this. We're doing it in .Net to allow a simple edit control on forms to send formatted emails. As such we have a RTF text box with a custom menu for creating the text, then we extract the RTF, convert it to HTML and add it as HTML content as the body of an email. The RTF to HTML conversion uses the code from this article: http://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter

Here's the wrapper code we use to tie this together - it simply takes an RTF input and directly returns an HTML output:

Imports Itenso.Rtf
Imports Itenso.Rtf.Support
Imports Itenso.Rtf.Parser
Imports Itenso.Rtf.Interpreter
Imports Itenso.Rtf.Converter.Image
Imports Itenso.Rtf.Converter.Html
Imports Itenso.Sys.Application
Namespace Email
  Public Class RtfToHtml

    Public Function Convert(inText As String) As String
      Dim struct = ParseRtf(inText)
      Dim doc = InterpretRtf(struct)
      Return ConvertHtml(doc)
    End Function


    Private Function ParseRtf(inText As String) As IRtfGroup
      Dim structureBuilder As New RtfParserListenerStructureBuilder
      Dim parser = New RtfParser(structureBuilder) With {.IgnoreContentAfterRootGroup = True}
      Dim source = New RtfSource(inText)
      parser.Parse(source)
      Return structureBuilder.StructureRoot
    End Function

    Private Function InterpretRtf(rtfStructure As IRtfGroup) As IRtfDocument
      Dim settings = New RtfInterpreterSettings With {.IgnoreDuplicatedFonts = True, .IgnoreUnknownFonts = True}
      Return RtfInterpreterTool.BuildDoc(rtfStructure, settings)
    End Function

    Private Function ConvertHtml(document As IRtfDocument) As String
      Dim settings As New RtfHtmlConvertSettings With {.Title = "Notification Of Shipment",
                                                       .IsShowHiddenText = False,
                                                       .UseNonBreakingSpaces = True}
      Dim converter = New RtfHtmlConverter(document, settings)
      'converter.StyleConverter = New RtfEmptyHtmlStyleConverter
      Return converter.Convert
    End Function

  End Class
End Namespace

Depending on your application you could simply wrap this up in an assembly and call it from VB6. We've done this in the past and it's reasonably straightforward. Again, more info if you think it might be useful to you

Upvotes: 3

Related Questions