Hello people,
how can I change the text color in a RichEdit control?
With frmMain.RichEdit1
.SelectionStart = 0
.SelectionLength = 5
' .SelectionColor = RGB(0, 0, 255) ' Blue ???
End with
Maybe it's not built in yet ?, can I do it in a different way?
I have a program where I need to set the color/font of certain RTF text. Here is the generic code that I use:
rtfText( hEdit, wszText, wszFontName, nFontSize, CFE_BOLD, colors.Black )
' ========================================================================================
' rtfText
' General purpose routine to set the font, size, effect, color for text to be entered.
' ========================================================================================
function rtfText( byval hEdit as HWND, _
byval wszText as CWSTR, _
byval wszFontName as CWSTR, _
byval nFontSize as long, _
byval nFontEffect as long = 0, _
byval nFontColor as COLORREF = 0 _
) as Long
dim hDC AS HDC
dim lRet AS LONG
dim cf AS CHARFORMAT2
DIM tlf AS LOGFONTW
dim stex as SETTEXTEX
stex.flags = ST_SELECTION or ST_UNICODE
hDC = GetDC(NULL)
EnumFontFamiliesW( hDC, byval wszFontName, cast(FONTENUMPROCW, @RichEdit_EnumFontFamProcW), cast(LPARAM, @tlf) )
ReleaseDC NULL, hDC
cf.cbsize = sizeof(cf)
cf.dwMask = CFM_FACE OR CFM_CHARSET or CFM_SIZE or _
CFM_BOLD OR CFM_ITALIC OR CFM_UNDERLINE OR CFM_STRIKEOUT or _
CFM_COLOR
cf.szFaceName = tlf.lfFaceName
cf.bCharSet = tlf.lfCharSet
cf.bPitchAndFamily = tlf.lfPitchAndFamily
cf.yHeight = nFontSize * 20
cf.dwEffects = nFontEffect
cf.crTextColor = nFontColor
SendMessage( hEdit, EM_SETCHARFORMAT, SCF_SELECTION, cast(LPARAM, @cf) )
RichEdit_SetTextExW( hEdit, @stex, wszText )
function = 0
end function
thanks Paul,
now i can move forward again.
Perhaps it is useful to add the function to WinFBE