Listbox flickers on form resize

N

nirdeshonline

Hi,
I have added a simple listbox in windows form under c# 2.0. It contains
a collection of approx 10 strings as list items. Now when i resize the
form whole listbox flickers.

Please tell me any feasible solution, i need to use a checked listbox
which also has same flickering problem on resize.

Thanks & Regards

Nirdesh Dabas
(e-mail address removed)
 
S

Stoitcho Goutsev \(100\)

Nirdesh,

When does the control flicker. I created a test application with listbox
containing 100 strings and I don't see any flickering. Either I don't
reproduce your case correctly or you have something esle going on in your
application. Can you post simple, but compilable sample that demonstrates
your problem.
 
N

nirdeshonline

hi,
You might have kept a listbox on a form. Thats fine. Please run the
application and try to resize the form. When you resize the form all
the contents of the listbox reloads and gives ample amount of
flickering.
Is there any solution to this problem.
Thanks & Regards
Nirdesh
 
R

Roman Wagner

Hi,

you may register to the form events ResizeBegin and -End. In
ResizeBegin event handler
call form.SuspendLayout and in ResizeEnd event handler call
form.ResumeLayout.
This is not tested but maybe it helps you.
 
N

nirdeshonline

PROBLEM STILL EXISTS
I can use

[DllImport("user32.dll")]

public static extern bool LockWindowUpdate(IntPtr hWndLock);

to lock the update at ResizeBegin and ResizeEnd but it stops the
redrawing of control and if i resize the form to minimum and stretch it
back i will find that the control i not painted and gives unwanted
image. I found similar flickering issue in listbox & CheckedListBox.

Even BeginUpdate and EndUpdate did not worked as it shows empty list
while resizing.

And your stated form events ResizeBegin and -End form.SuspendLayout
using form.ResumeLayout do not work for listbox and checkedlistbox. :(
 
S

Stoitcho Goutsev \(100\)

What I did I anchored the control so it resizes when the form resizes. I
resized the form and as a matter of fact I can see some hardly noticable
flickering on the elements on the top, but nothing so drastic, but yes there
is some filickering. I find it strange that on my test only the first
element in the lisbox flickers - not the first visible, but the first in the
list. There are some thinks that looks like reduce the flicker, but doesn't
get rid of it completely:
1. Set IntegralHeight to *false* it looks like there is some problem and the
control height changes without visible reason as the list box resizes.
2. Try to double buffer the control. I'd expect this to remove the
flickering, but it looks like it only reduces it a bit. To do that you need
to inherit from the control and in the constructor to set DoubleBuffered
protected property to *true*.

If this doesn't give you good result trye using ListView. I haven't tried,
but as a more complex control it may behave better.


--
HTH
Stoitcho Goutsev (100)

This flickering can be removed if I inherit from the listbox and make it
double buffered.
 
N

nirdeshonline

Hi thanks for the reply,
The problem i stated is specific to tabcontrol. Even i noticed it late
.. when i dock fill
tabcontrol on a form and put a listbox in docked tabcontrol. THEN AT
RESIZE of the
form, listbox as well as the tabcontrol flickers badly.
Please tell any possible solution
 
N

nirdeshonline

Stoitcho said:
What I did I anchored the control so it resizes when the form resizes. I
resized the form and as a matter of fact I can see some hardly noticable
flickering on the elements on the top, but nothing so drastic, but yes there
is some filickering. I find it strange that on my test only the first
element in the lisbox flickers - not the first visible, but the first in the
list. There are some thinks that looks like reduce the flicker, but doesn't
get rid of it completely:
1. Set IntegralHeight to *false* it looks like there is some problem and the
control height changes without visible reason as the list box resizes.
2. Try to double buffer the control. I'd expect this to remove the
flickering, but it looks like it only reduces it a bit. To do that you need
to inherit from the control and in the constructor to set DoubleBuffered
protected property to *true*.

If this doesn't give you good result trye using ListView. I haven't tried,
but as a more complex control it may behave better.


--
HTH
Stoitcho Goutsev (100)

This flickering can be removed if I inherit from the listbox and make it
double buffered.
 
N

nirdeshonline

The problem i stated is specific to tabcontrol. Sorry i stated it
inappropriately earlier . when i dock fill
tabcontrol on a form and put a listbox there. THEN AT RESIZE of the
form, listbox as well as the tabcontrol flickers badly.
Please tell any possible solution
 

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