Font color in RichTextBox problem
I'm trying to set the font color in a richtextbox (rtbSample) based on the position of 3 scrollbars (scrRGB(0,1,2))and it's rgb value in a textbox (txtRGB) but it just won't work. Any ideas?
Code:
Private Sub scrRGB_Change(Index As Integer)
Dim CombinedValue As Long
CombinedValue = RGB(scrRGB(0).Value, scrRGB(1).Value, scrRGB(2).Value)
txtRGB.Text = "&H" & CombinedValue
picRGB.BackColor = CombinedValue
End Sub 'scrRGB_Change(Index As Integer)
Private Sub txtRGB_Change()
rtbSample.SelStart = 0
rtbSample.SelLength = Len(rtbSample.Text)
rtbSample.SelColor = txtRGB.Text
End Sub
Private Sub txtRGB_GotFocus()
If Len(txtRGB.Text) > 0 Then
txtRGB.SelStart = 0
txtRGB.SelLength = Len(txtRGB.Text)
End If
End Sub 'txtRGB_GotFocus()
Re: Font color in RichTextBox problem
Your conversion of an RGB Colour to a Hex Colour is incorrect.
Create the Hex Colour by concatenating the Hex value of each scroll bar but note that Hex Colours are in the form BBGGRR.
txtRGB.Text = "&H" & Format$(Hex(scrRGB(2).Value), "00") & Format$(Hex(scrRGB(1).Value), "00") & Format$(Hex(scrRGB(0).Value), "00")
or simply set the rtbSample.SelColor = picRGB.BackColor