Search code examples
c#stringpictureboxtransparentdrawstring

When I try to place a string using pictureBox with a transparent background, I get ugly white pixels around my string. How to solve this problem?


I removed backColor from the form and added a pictureBox. After that I'm trying to draw a string. But It looks really ugly with these white pixels. Could y'all help me, please?

Here is a screenshot of the problem: https://i.sstatic.net/MKJS5.png

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawString("Hello World!", new Font("Microsoft Sans Serif", 20f), new SolidBrush(Color.Black), 20, 20);
    }
}

Solution

  • Thank y'all so much! I've solved the problem with:

    e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;