3

I am trying to display a label on a form where the form is transparent.

I am getting an outline around the label's text as seen in the below image:

enter image description here

The black is the background of a different form.

Here is my form code:

label1.ForeColor = System.Drawing.Color.Red;
label1.BackColor = System.Drawing.Color.Transparent;

BackColor = System.Drawing.Color.White;
TransparencyKey = System.Drawing.Color.White;
TopMost = true;

How can I display the label without the white as seen in the above image?

Simon
  • 7,991
  • 21
  • 83
  • 163
  • That's normal, the text is anti-aliased. Pixels close to the letters are various shades of red. Not pure white and therefore not transparent. You cannot use a Label if you want to do this, you'll have to paint it yourself. – Hans Passant Mar 31 '16 at 05:28
  • Refer [this](http://stackoverflow.com/questions/2609520/how-to-make-text-labels-smooth). It will help! – Bharat Gupta Mar 31 '16 at 06:32

1 Answers1

0

I mentioned a link in the comments. Then I tried it as well. It works. Check out the screenshot below. The first text is from the general Label while the second one is from the CustomLabel from the post.

enter image description here

Just to summarize what needs to be done, I would quote from that post itself. We need to create a CustomLabel class inheriting from System.Windows.Forms.Label:

public partial class CustomLabel : Label
{
    private TextRenderingHint _hint = TextRenderingHint.SystemDefault;   
    public TextRenderingHint TextRenderingHint
    {
        get { return this._hint; }
        set { this._hint = value; }
    }        

    protected override void OnPaint(PaintEventArgs pe)
    {            
        pe.Graphics.TextRenderingHint = TextRenderingHint;
        base.OnPaint(pe);
    }
}

We would then build this and this CustomLabel would appear in Toolbox for us to use it. After dragging it onto our form we need to set its TextRenderingHint property to AntiAlias

Community
  • 1
  • 1
Bharat Gupta
  • 2,628
  • 1
  • 19
  • 27