Option Explicit
Private Sub ColorTags(rch As RichTextBox)
Dim txt As String
Dim tag_open As Integer
Dim tag_close As Integer
txt = rch.Text
tag_close = 1
Do
' Se var taggen starar.
tag_open = InStr(tag_close, txt, "<")
If tag_open = 0 Then Exit Do
' Se var taggen slutar.
tag_close = InStr(tag_open, txt, ">")
If tag_open = 0 Then tag_close = Len(txt)
' Färglägg taggen
rch.SelStart = tag_open - 1
rch.SelLength = tag_close - tag_open + 1
rch.SelColor = vbRed
Loop
End Sub
Private Sub Form_Load()
Dim fnum As Integer
Dim txt As String
' Flytta den gömda RTF-boxen så den inte kan ses.
rchHidden.Move -rchHidden.Width - 120, 0
' Laddar in en rtf-fil
'rchHidden.LoadFile App.Path & "\demo.rtf", rtfRTF
' Laddar in en html-fil
fnum = FreeFile
Open App.Path & "\demo.htm" For Input As fnum
txt = Input$(LOF(fnum), fnum)
rchHidden.Text = txt
Close fnum
' Färglägg HTML taggarna
ColorTags rchHidden
' Kopierar resultatet till den visande
' RichTextboxen
rchHidden.SelStart = 0
rchHidden.SelLength = Len(rchHidden.Text)
rchVisible.SelStart = 0
rchVisible.SelLength = Len(rchVisible.Text)
rchVisible.SelRTF = rchHidden.SelRTF
End Sub
Private Sub Form_Resize()
' Anpassar kontrollens storlek till formen
rchVisible.Move 0, 0, ScaleWidth, ScaleHeight
End Sub