Label: how to avoid flicker?

  • Thread starter Thread starter Boris Nienke
  • Start date Start date
B

Boris Nienke

Hi,

i need to update a Label.Text very often using C#.
This works great - but it is flickering a lot (not very nice to look at)

How can i use a kind of "DoubleBuffer" with the CF?

thank you

Boris
 
Boris said:
Hi,

i need to update a Label.Text very often using C#.
This works great - but it is flickering a lot (not very nice to look at)

How can i use a kind of "DoubleBuffer" with the CF?

thank you

Boris

You might try overriding OnPaintBackground and not calling the base
class implementation. This often causes a lot of flickering for me. Plus
it's a lot easier than implementing double buffering.

--

..o0O0o.__.o0O0o.__.o0O0o.__.o0O0o.__.o0O0o.__.o0O0o.__.o0O0o.
| Matt Kunze Sometimes there's a point.|
| Build Master Fooly Fool This is not one of those |
| DataSplice Software Developer times. |
=============================================================
 
Boris said:
sorry for this - maybe very stupid - question, but i'm very new C# (few
days yet)

How/Where can i override this Event?
I think i need to create my own Label-Class? Where/How and how to use it
then?

thank you very much

Boris

It's not that difficult, actually. Just create a new class 'LabelEx' and
have:

using System;
using System.Windows.Forms;

namespace YourNamespace
{
public class LabelEx : Label
{
public LableEx()
{
}

protected override void OnPaintBackground(PaintEventArgs e)
{
// don't call base.OnPaintBackground(e) so things don't flicker
}
}
}

Now in you form create new LabelEx objects instead of Label objects and
it will use your extended class

--

..o0O0o.__.o0O0o.__.o0O0o.__.o0O0o.__.o0O0o.__.o0O0o.__.o0O0o.
| Matt Kunze Sometimes there's a point.|
| Build Master Fooly Fool This is not one of those |
| DataSplice Software Developer times. |
=============================================================
 
I do not beleive OnPaintBackground is called for labels.
You must inherit from control to use this technique which
also requires you to do more to acheive the original label
capabilities. Also, you will no longer be able to use the
designer to locate your custom label on the form.
 
Wow, this sounds a bit complex...

havn't tried the "LabelEx" thing now but work-around the problem by
drawing the text to a Bitmap and then assigning it to a PictureBox.

I need more knowledge about the IDE, and how to install new (own)
controls so that i can use them in the designer... everything else is
not so good...

thank you anyway - as soon as i know how to install my own controls to
the IDE i will try the trick "not erase the background" (but i wonder if
the label is getting darker and darker then - because the old text
wouldn't be erased?)

boris
 
Back
Top