0

I'm trying to do a custom label class with transparency and I was searching a lot of articles about this but my case is different cause I'm trying to do a countdown with a transparent label, then when I use the example code below success flickering. I use a timer with interval set to 100 then change the text custom label. I don't know what can I do to get better performance when refreshing, any idea?

class CustomLabel : Label
{
    public CustomLabel()
    {
        this.SetStyle(ControlStyles.Opaque, true);
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
    }

    protected override System.Windows.Forms.CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x20;
            return cp;
        }
    }
    public override string Text
    {
        get
        {
            return base.Text;
        }
        set
        {
            base.Text = value;
            RecreateHandle();
        }
    }
}
svick
  • 236,525
  • 50
  • 385
  • 514
Eldoran
  • 51
  • 6

1 Answers1

1

It flickers because of the RecreateHandle() call. That re-creates the native Windows window, flicker is inevitable as you see the old window getting destroyed and the new one created. Just remove the call, it isn't necessary.

And don't forget to take advantage of the built-in support for transparency in the Label control.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536