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 tex开发者_运维技巧ts 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
Use the Graphics object from PaintEventArgs.
Change
System.Drawing.Graphics formGraphics = this.CreateGraphics();
To
System.Drawing.Graphics formGraphics = e.Graphics;
And remove
formGraphics.Dispose();
精彩评论