c# - visual c# - onPaint 和透明度

标签 c# .net winforms transparency onpaint

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

这是我的代码片段:

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

提前致谢

最佳答案

使用来自 PaintEventArgs 的 Graphics 对象。

改变

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

System.Drawing.Graphics formGraphics = e.Graphics;

并删除

formGraphics.Dispose();

关于c# - visual c# - onPaint 和透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2622997/

相关文章:

c# - 类库中定义的内容在 ClickOnce 部署期间不传输

c# - 显示来自多个线程的单个对话框

c# - ASP.NET MVC 3 : Is there a way to get a controller's string Name from its Type?

c# - 通过坐标获取窗口

c# - 性能有什么问题吗?

.net - Rider 无法检测 Ubuntu 上的 .NET core 安装

c# - 如何从 Dotnet EF 中删除唯一索引?

c# - 如何从桌面应用程序知道某个进程是否在 Windows CE 设备上运行

c# - 使用 Dapper 多次执行存储过程?

.net - WPF 中的数据绑定(bind)以何种方式改进了过去的框架?