Visual C # - onPaint and transparency

I am making a simple shape with two translucent texts and I put it on a drawing event. only when I expand the form, the texts become darker and grainy. In fact, I want a darker color, but not a grainy effect.

here is my code snippet:

private void sbfToolBox_Paint(object sender, PaintEventArgs e)
{
    System.Drawing.Graphics formGraphics = this.CreateGraphics();
    formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
    string drawString = "tekst";
    System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 50);
    Color color_red = Color.FromArgb(30, 100, 0, 0);
    Color color_cyan = Color.FromArgb(30, 0, 100, 100);
    System.Drawing.SolidBrush brush_red = new System.Drawing.SolidBrush(color_red);
    System.Drawing.SolidBrush brush_cyan = new System.Drawing.SolidBrush(color_cyan);
    float x = 0.0F;
    float x2 = 20.0F;
    float y = 50.0F;
    formGraphics.DrawString(drawString, drawFont, brush_red, x, y);
    formGraphics.DrawString(drawString, drawFont, brush_cyan, x2, y);
    drawFont.Dispose();
    brush_red.Dispose();
    brush_cyan.Dispose();
    formGraphics.Dispose();
}    

early

+3
source share
1 answer

Use a Graphics object from PaintEventArgs.

Edit

System.Drawing.Graphics formGraphics = this.CreateGraphics();

For

System.Drawing.Graphics formGraphics = e.Graphics;

And delete

formGraphics.Dispose();
+2
source

Source: https://habr.com/ru/post/1740777/


All Articles