RichTextBox flicker reduction methods?

Ö

Özden Irmak

Hello,

One of the WindowsForms controls that I developed uses a richtextbox as an
editor in one of it's properties. As it does syntaxhighlighting, I get a lot
of flicker at this operation. Using LockWindowUpdate API helps a lot but at
the same time causes the desktop to flicker like a hell.

I would like to ask if anybody knows a better method?

Regards,

Özden Irmak
 
G

Guest

One of the WindowsForms controls that I developed uses a richtextbox as an
editor in one of it's properties. As it does syntaxhighlighting, I get a lot
of flicker at this operation. Using LockWindowUpdate API helps a lot but at
the same time causes the desktop to flicker like a hell.

I handle the flicker problem with a second control (another rtb or a label).
I keep this control at the same size and location of my rtb, but behind in
the z-order. When I want to do operations that cause flicker, I use
BringToFront, do the color highlighting while the rtb is behind in z-order,
and then do SendToBack. This technique stops flicker completely provided
that there are no paint operations between BringToFront and SendToBack. That
means no DoEvents, no Refresh, or anything else that might cause a paint.
 
G

Guest

Wondering how you are walking through the text? If you are using rtb
functions like find then I would like to suggest you try using instr() You
can search for the text, get the start and end positions and then simply set
the color on the selection. As an example:

SelectionStart = nStartPos
SelectionLength = nEndPos - nStartEnd + 1
SelectionColor = Color.Purple

I developed a Richtextbox control that color codes HTML much the same as
frontpage and other applications. I get no flicker using this method...it's
much much faster
 
G

Guest

Wondering how you are walking through the text? If you are using rtb
functions like find then I would like to suggest you try using instr() You
can search for the text, get the start and end positions and then simply set
the color on the selection. As an example:

SelectionStart = nStartPos
SelectionLength = nEndPos - nStartEnd + 1
SelectionColor = Color.Purple

I developed a Richtextbox control that color codes HTML much the same as
frontpage and other applications. I get no flicker using this method...it's
much much faster

I do it using Instr, so I get the speed advantage you mention.

The flicker that I have comes from setting .SelectionStart and
..SelectionLength in an rtb such that windows decides to scroll the new
selection into view. The best I was able to achieve without my
sendtoback-bringtofront gimmick was setting rtb's Enabled to false during
highlighting, then back to true when done. This got rid of scrolling
flicker, but it did yield a visual artifact that looked like graying out a
control followed by painting. All visual problems went away with the
back-front gimmick.

I haven't tried Herfried's suggestion since I prefer not using win32 apis
whenever possible. I have tried api LockWindowUpdate, and I had a snowy
flicker-like effect.

Do you have any visual problems in your html highlighter when the text is
large relative to the window size? I'm curious about how you do things in
this area. Much has been written about the topic of flicker or other
undesirable visual effects, and after much trial and error, I settled on the
back-front gimmick. Maybe you have a better way.
 
G

Guest

The only special thing I do is that when I initially populate the Tichtext
box I only color the visible text. If the user pages down then I color that
page which gets away from any of the page moving without the user. Then while
the user is editing the text I recolor the line they are on. So, I guess the
trick I use is to do is to work on the smallest area I can
 
G

Guest

The only special thing I do is that when I initially populate the Tichtext
box I only color the visible text. If the user pages down then I color that
page which gets away from any of the page moving without the user. Then while
the user is editing the text I recolor the line they are on. So, I guess the
trick I use is to do is to work on the smallest area I can

That sounds like it will work without any unwanted visual effects. I
highlight about 500 lines of text, and I don't do anything as he
scrolls/pages. My gimmick solves the flicker problem for this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top