[英]drawing a string with a transparent background using C#?
g.DrawString的标准方法创建灰色背景。 因此,如果在表单上覆盖另一个字符串,则它的一部分显示为灰色。
我的问题是,有没有办法绘制透明背景的字符串? 我希望能够覆盖字符串,但仍然能够看到它们。
你确定吗?
这是一个教程,可能会有所帮助:
http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-how-to-draw-text-on-an-image
(编辑)
尝试从基础开始:我刚刚创建了一个新的表单应用程序,并将Form1中的代码更改为此:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Paint += new PaintEventHandler(Form1_Paint);
}
void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString("hello", new Font("Arial", 36), new SolidBrush(Color.FromArgb(255,0,0)), new Point(20,20));
e.Graphics.DrawString("world", new Font("Arial", 36), new SolidBrush(Color.FromArgb(0,0,255)), new Point(30,30));
}
}
它可以按预期工作,并具有透明的文本背景。
不发布代码就无法诊断。 默认情况下,Graphics.DrawString 不画背景。 此样本表单演示了这一点:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e) {
e.Graphics.DrawString("Underneath", this.Font, Brushes.Black, 0, 0);
e.Graphics.DrawString("Overlap", this.Font, Brushes.Black, 25, 5);
base.OnPaint(e);
}
}
请注意,“重叠”字符串如何不会擦除“下方”字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.