Reputation: 476
The problem: I need to add some context along with RichTextBox content.
Starting from this post I have come to the conclusion according to dr-null's suggestion to have this context info placed on the non-client area and keep the text content into the RichTextBox client area, because using a technique similar to this has heavy painting issues when scrolling horizontally.
Yet, after painting in the non-client area, I need to synchronize that with the RichTextBox content, but I fail to find a way to handle this in the WndProc. In my tests, the only case that fails is when vertically or horizontally scrolling, because the non-client area messages to WndProc come mostly when the scrollbars change their size only, but not when scrolling. I say mostly because they do not come in all the scrollbars size change cases. Scrolling seems to not trigger at all something in WndProc either.
My WndProc:
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case WM_NCCALCSIZE
OnNcCalcZise(m)
Case WM_NCPAINT
OnNcPaint(m) ' Occurs in certain cases like initial paint or scroll size bars changes due to adding longer lines than could be displayed at once or more lines than could be displayed at once in the RichTextBox
End Select
MyBase.WndProc(m) ' In order to have the scrollbars painted, must call this here. Why?
End Sub
I need to repaint the non-client area according to the position in the RichTextBox.
So, if I manage to paint the non-client area in certain cases, how could this be extended when scroilling/editing text in the RichTextBox?
Also, working with the non-client area seems to prevent the scrollbars painting. How is this correctly done? Edit: Following this issue, I've found that after handling WM_NCPAINT, calling Invalidate() helps. Yet, the painting seems slow, but all the control elements are drawn now. The non-client routines are from here, the only difference being the fact that I have removed the icon part and the non-client area is a band in the left part of the control.
However, there should be an algorithm of how this should be done with regards to what to call and when around a particular implementation - at least when nothing is painted over some standard components. For example, I see in some proposed implementations here that the code calling the base WndProc on the Case Else select branch, but in this case does not paint the scrollbars anymore, so it must call WndProc again (probably this applies in some of the cases, but I am not sure now).
Digging further, I see a problem regarding scrolling, so either way (regarding the referred options above), must handle the scrolling events. Working with the non-client ara seems to be in conflict with the paint event and the client area is affected in some cases when trying to keep the non-client area in sync with the content area. Yet, the non-client area helps to reduce the flicker. The dilemma for me is how to be able to:
Upvotes: 0
Views: 98