【问题标题】:visual c# - onPaint and transparencyvisual c# - onPaint 和透明度
【发布时间】:2011-02-07 01:21:33
【问题描述】:

我正在制作一个带有两个半透明文本的简单表格 我把它放在一个绘画活动中。 只是,当我扩大表格时,文本会变得更暗和有颗粒感。 实际上我想要更深的颜色而不是颗粒效果。

这是我的代码 sn-p:

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

提前致谢

【问题讨论】:

    标签: c# .net winforms transparency onpaint


    【解决方案1】:

    使用 PaintEventArgs 中的 Graphics 对象。

    改变

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

    System.Drawing.Graphics formGraphics = e.Graphics;
    

    然后删除

    formGraphics.Dispose();
    

    【讨论】:

    • 谢谢,但我还有一点其他问题,我创建了一个从按钮调用的函数,但在该函数中我需要 e.Graphics 我如何创建一个新的?
    猜你喜欢
    • 1970-01-01
    • 2010-12-21
    • 2012-03-28
    • 2010-09-11
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多