Visual C# - OnPaint和透明度

3
我正在制作一个包含两个半透明文本框的简单表单,并将其放在绘图事件中。但是,当我拉宽表单时,文本框会变得更暗和多粒度。实际上,我想要的是更暗的颜色但不要多粒度效果。
以下是我的代码片段:
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

使用来自PaintEventArgs的Graphics对象。

更改

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

To

System.Drawing.Graphics formGraphics = e.Graphics;

并删除

formGraphics.Dispose();

谢谢,但我有一个小问题。我创建了一个可以从按钮调用的函数,但在函数中我需要 e.Graphics,我该如何创建一个新的? - ecross

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接