views:

177

answers:

1

hello everybody,

I am making a simple form with two semi-transparent texts and i put it in a paint event. only, when I wider the form, the texts turn darker and grainy. actualy I want the darker color but not the 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();
}    

thanks in advance

+1  A: 

Use the Graphics object from PaintEventArgs.

Change

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

To

System.Drawing.Graphics formGraphics = e.Graphics;

And remove

formGraphics.Dispose();
Chris Persichetti
thank you, but i have a little other question, i made a function to call from a button, but in the function i need the e.Graphics how do i create a new one?
ecross