VB projects - Set font color in RichTextBox
Description: using RTF to change RichTextBox font color
Minimum requirements: VB6
Download: source code
Screenshot:

Project: EXE
Controls: ComboBox cmb (Style = 2 'Dropdown List), RichTextBox rtf
Additional references: none
Code:
Option Explicit
Dim sColors As String
Private Sub cmb_Click()
Dim s As String
s = Hex(QBColor(cmb.ListIndex))
s = String(6 - Len(s), "0") & s
rtf.SelStart = 0
rtf.SelLength = Len(rtf.Text)
rtf.SelColor = vbWhite
rtf.SelRTF = "{{\colortbl;\red" & Val("&H" & Right(s, 2)) & "\green" & Val("&H" & _
Mid(s, 3, 2)) & "\blue" & Val("&H" & Left(s, 2)) & ";}" & "{\highlight1 " & rtf.Text & "}}"
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 15
cmb.AddItem i
Next
cmb.ListIndex = 0
End Sub
|