The attached code shows a way to use FillRect and DrawText to create line numbers and alternating line colors in a RichEdit control - but it's not compatible with allowing the user to type in text of their own and maintain the line #'s/colors.
Other than writing a custom control from scratch (or use something like the custom EDM32 control) is there a way to maintain the line #'s and line colors wihle the user edits - while continuing to use the standard RichEdit control?
I've seen hints of being able to set a background image for a RichEdit control, but cannot find any details.
I've also seen the idea of making the RichEdit background transparent and of having an image control (which contains the #'s/colors) under the RE. I've not tried anything like this yet.
Here's what the control looks like before editing, with line numbers and line colors drawn in.

And here's the basic code to generate the numbers/colors.
Other than writing a custom control from scratch (or use something like the custom EDM32 control) is there a way to maintain the line #'s and line colors wihle the user edits - while continuing to use the standard RichEdit control?
I've seen hints of being able to set a background image for a RichEdit control, but cannot find any details.
I've also seen the idea of making the RichEdit background transparent and of having an image control (which contains the #'s/colors) under the RE. I've not tried anything like this yet.
Here's what the control looks like before editing, with line numbers and line colors drawn in.

And here's the basic code to generate the numbers/colors.
Code:
'Compilable Example: #Compile Exe #Dim All #Include "Win32API.inc" #Include "RichEdit.inc" #Include "CommCtrl.inc" Global hDlg As Dword, hRichEdit As Dword, hDC As Dword %ID_RichEdit = 500 Function PBMain() As Long Local style&, buf$ buf$ = "Rats! This text will covered!" style& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _ Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop Dialog New Pixels, 0, "Test Code",300,300,400,400, %WS_OverlappedWindow To hDlg Control Add Button, hDlg, 100,"Push", 30,10,140,20 LoadLibrary("riched32.dll") : InitCommonControls Control Add "RichEdit", hDlg, %ID_RichEdit, buf$,20,40,340,340, style&, %WS_Ex_ClientEdge Control Handle hDlg, %ID_RichEdit To hRichEdit hDC = GetDC(hRichEdit) SendMessage hRichEdit, %EM_SETMARGINS, %EC_LEFTMARGIN, 70 Dialog Show Modal hDlg Call DlgProc End Function CallBack Function DlgProc() As Long Select Case CB.Msg Case %WM_Paint DrawStuff Case %WM_Destroy ReleaseDC (hRichEdit, hDC) Case %WM_Command If CB.Ctl = 100 Then DrawStuff End Select End Function Sub DrawStuff Local txtZ As Asciiz*10, R As Rect, temp$, i As Long, j As Long For i = 1 To 300 Step 30 R.nleft = 40 : R.ntop = i R.nright = 350 : R.nbottom =i+15 FillRect hDC, R, %Color_BtnFace+1 'FillRect R.nleft = 40 : R.ntop = i+15 R.nright = 350 : R.nbottom =i+30 FillRect hDC, R, %Color_GrayText+1 'FillRect Next i For i = 1 To 300 Step 15 Incr j temp$ = LTrim$(Str$(j)) R.nleft = 5 : R.ntop = i R.nright = 30 : R.nbottom =i+20 DrawText hDC, ByVal StrPTR(temp$), Len(temp$), R, %DT_Left Next i End Sub
Comment