Visual C # - OnPaint и прозрачность - PullRequest
3 голосов
/ 12 апреля 2010

Я делаю простую форму с двумя полупрозрачными текстами и я положил его в событие краски. только когда я расширяю форму, тексты становятся темнее и зернистее. на самом деле я хочу более темный цвет, но не зернистый эффект.

вот мой фрагмент кода:

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();
}    

спасибо заранее

1 Ответ

2 голосов
/ 13 апреля 2010

Использовать объект Graphics из PaintEventArgs.

Изменение

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

К

System.Drawing.Graphics formGraphics = e.Graphics;

И удалить

formGraphics.Dispose();
...