On Wed, 20 Aug 2008 02:48:01 -0700, Ray Mitchell
<Ra*****************@meanoldteacher.comwrote:
[...]
I need a RichTextBox because I color-code my messages.
Ah...this sounds familiar. I think we've talked about this problem with
you before, right? :)
[...] It
only has one basic problem (other than being slow) and that is the
flickering
dirves you crazy. Of course I've fought this flickering issue with every
application like this I've ever done and never have solved it (although
I'm
sure the solution must be simple). I have set the DoubleBuffered
property to
true, but that has never had any effect whatsoever in any of these
applications.
Right. DoubleBuffered addresses a particular kind of "flickering". That
is, the erasing of the background before redrawing the new contents of the
control or other kinds of "compositing" operations. But if all that's
happening is that the control has to keep redrawing itself because it is
repeatedly changing, some other technique would be needed (such as somehow
disabling updates altogether until what's considered a single change has
been completed, even if that single change involves multiple logical
changes).
I've looked into of just rewiting the visible area of the
control rather than actually letting it redraw line-at-a-time as the
whole
set is re-appended, but I'm not proficient enough at this stuff to
actually
pull that off yet. So my applications just flicker away! Suggestions
are
welcome.
Well, the code I directed you to could trivially be changed to support
per-line coloring. I've already got a "DisplayLine" data structure in
there that tracks the line information. Right now the only
client-provided piece of information is the string itself, but you could
easily add a Color to that too (passing it in to the Append() or
AppendLine() methods), and then create the Brush used for drawing each
line of text using the Color.
Alternatively, you might consider using the SelectionStart,
SelectionLength, and SelectedText properties to remove text at the
beginning of the control rather than doing the multi-step process. Just
set the SelectionLength and SelectedText values so that the selection
contains exactly the text you want removed, and then set SelectedText to
String.Empty.
Of course, you could just not worry about removing text at the beginning
of the control. Without knowing your specific needs, it's hard to know
whether that's appropriate or not. But the theoretical maximum content of
the RichTextBox control is quite large, and if you know for sure you'll
never come close to that, maybe the best solution is to just not worry
about it. :)
Pete