Yet again another issue with resizing, like many others I have used the CreateParams method of setting up a transparent label, everything looks and works great… except for when the form is re-sized the text vanishes!
Anyone have any ideas? The control is there but the text isn’t showing as if I minimize the form and then restore it shows!
public class TransparentLabel : Label
{
public TransparentLabel()
{
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
}
protected override CreateParams CreateParams
{
get
{
CreateParams parms = base.CreateParams;
parms.ExStyle |= 0x20; // Turn on WS_EX_TRANSPARENT
return parms;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
if (base.BackgroundImage == null)
{
e.Graphics.DrawRectangle(new System.Drawing.Pen(this.BackColor, 1), e.ClipRectangle);
}
else
{
base.OnPaintBackground(e);
}
}
}
The quick solution to this was to use a Link Label control, set its background to transparent and set the link length to 0.