Og hvis du også gerne vil kunne fjerne farverne igen skal indsætte noget mere:
dette også stå i (general declarations)
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
og dette er så 2 subs mere
Public Sub UnHighLight(mForm As Form, mRTF As RichTextBox, Optional mHighLightColor As Long, Optional AllHighlighting As Boolean, Optional DontLock As Boolean)
Dim tmpRTF As String, z As Long
Dim curvl As Long, HLNum As Long
curvl = SendMessage(mRTF.hWnd, EM_GETFIRSTVISIBLELINE, ByVal 0&, ByVal 0&)
If InStr(1, mRTF.TextRTF, "\\highlight") = 0 Then Exit Sub
If Not DontLock Then LockWindowUpdate mForm.hWnd
If Not AllHighlighting Then
'find the color index in the Colortable
'of the desired color
GetColorTable mRTF
For z = 1 To ColorColl.Count
If ColorColl(z) = mHighLightColor Then
HLNum = z - 1
Exit For
End If
Next
'remove such entries from the RTF code
tmpRTF = mRTF.TextRTF
tmpRTF = Replace(tmpRTF, "\\highlight" & HLNum & " ", "")
Else
'color doesn't matter - just remove any highlighting
tmpRTF = Replace(mRTF.TextRTF, "\\highlight0 ", "")
tmpRTF = Replace(tmpRTF, "\\highlight0", "")
z = 1
If InStr(1, tmpRTF, "\\highlight") <> 0 Then
Do
If InStr(1, tmpRTF, "\\highlight" & z) <> 0 Then
tmpRTF = Replace(tmpRTF, "\\highlight" & z & " ", "")
tmpRTF = Replace(tmpRTF, "\\highlight" & z & "", "")
End If
If InStr(1, tmpRTF, "\\highlight") = 0 Then Exit Do
z = z + 1
Loop
End If
End If
'return the adjusted RTF code to the richtextbox
mRTF.TextRTF = tmpRTF
SetScrollPos mForm, mRTF, curvl, True
If Not DontLock Then LockWindowUpdate 0
End Sub
Public Sub SetScrollPos(mForm As Form, mRTF As RichTextBox, mPos As Long, Optional DontLock As Boolean)
Dim CurLineCount As Long, curvl As Long, lastvl As Long
'how many lines?
CurLineCount = SendMessage(mRTF.hWnd, EM_GETLINECOUNT, ByVal 0&, ByVal 0&)
'what's the current top line?
curvl = SendMessage(mRTF.hWnd, EM_GETFIRSTVISIBLELINE, ByVal 0&, ByVal 0&)
If Not DontLock Then LockWindowUpdate mForm.hWnd
'use a "PageUp" or "PageDown" for a few big jumps to get close to our target line
If mPos < curvl Then
Do Until curvl < mPos
SendMessage mRTF.hWnd, EM_SCROLL, 2, 0
curvl = SendMessage(mRTF.hWnd, EM_GETFIRSTVISIBLELINE, ByVal 0&, ByVal 0&)
If curvl = 0 Or curvl = CurLineCount Then Exit Do
Loop
Else
Do Until curvl > mPos
SendMessage mRTF.hWnd, EM_SCROLL, 3, 0
curvl = SendMessage(mRTF.hWnd, EM_GETFIRSTVISIBLELINE, ByVal 0&, ByVal 0&)
If curvl = 0 Or curvl = CurLineCount Or lastvl = curvl Then Exit Do
lastvl = curvl
Loop
End If
'Now do some fine adjustment line by line to get
'it exactly right
Do Until curvl = mPos
If mPos < curvl Then
SendMessage mRTF.hWnd, EM_SCROLL, 0, 0
Else
SendMessage mRTF.hWnd, EM_SCROLL, 1, 0
End If
curvl = SendMessage(mRTF.hWnd, EM_GETFIRSTVISIBLELINE, ByVal 0&, ByVal 0&)
If curvl = 0 Or curvl = CurLineCount Or lastvl = curvl Then
If curvl = 0 Then SendMessage mRTF.hWnd, EM_SCROLL, 0, 0
Exit Do
End If
lastvl = curvl
Loop
If Not DontLock Then LockWindowUpdate 0
End Sub