【问题标题】:How can I set the font colour?如何设置字体颜色?
【发布时间】:2014-04-25 05:11:28
【问题描述】:

我正在使用 Visual C#。在图片上叠加文字时,如何设置字体颜色?

graphicsImage.DrawString(textBox1.Text,
new Font("Arial", 12, FontStyle.Bold)
SystemBrushes.WindowText, new Point(10, 210));        

【问题讨论】:

  • 你能添加你有问题的 xaml/aspx 吗?

标签: c# text fonts colors overlay


【解决方案1】:

尝试像这样使用SolidBrush,你会得到红色字体:

graphicsImage.DrawString(textBox1.Text, new Font("Arial", 12, FontStyle.Bold), new SolidBrush(Color.Red), new Point(10, 210));

【讨论】:

    【解决方案2】:

    没有FontColor 属性,您应该使用正确的Brush。 不要忘记处理 IDisposable,在你的情况下:

      using (Brush brush = new SolidBrush(Color.Red)) { // <- Let your text be red
        using (Font font = new Font("Arial", 12, FontStyle.Bold)) {
          // Paint the text with selected
          //  font - Arial 12 Bold
          // brush - solid red
          graphicsImage.Graphics.DrawString(
            textBox1.Text,       // <- what (text)
            font,                // <- font
            brush,               // <- color
            new Point(10, 210)); // <- where
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-14
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 2016-04-12
      • 2010-09-27
      • 2016-09-30
      相关资源
      最近更新 更多