【问题标题】:Declaring a Brushes variable for input为输入声明一个 Brushes 变量
【发布时间】:2014-02-07 03:35:03
【问题描述】:

我目前有以下方法

public void printTitle(string title){
    // settings for stringformat
    g.DrawString(title, drawFontTitle, Brushes.White, x, y, stringFormatTitle);
}

但是,我试图让输入定义标题的颜色,如下所示:

public void printTitle(string title, Brushes titleColor){
    // settings for stringformat
    g.DrawString(title, drawFontTitle, titleColor, x, y, stringFormatTitle);
}

它会这样使用:

printTitle("Title Text", Brushes.White);

但是,我认为在声明导致错误的 Brushes titleColor 时存在问题。

【问题讨论】:

  • 您(和其他所有人)可以通过单击您姓名旁边的 'edited... ago' 链接查看谁编辑了什么 bij。所以没有必要添加感谢和其他噪音.. ;-)

标签: c# graphics colors bitmap


【解决方案1】:

问题是您传递的Brushes.Color 的值是brush 类型,而您的方法将Brushes 作为参数类型:

public void printTitle(string title, Brushes titleColor)
{
    // settings for stringformat
    g.DrawString(title, drawFontTitle, titleColor, x, y, stringFormatTitle);
}

所以用这个代替它会起作用:

public void printTitle(string title, Brush titleColor)
{
    // settings for stringformat
    g.DrawString(title, drawFontTitle, titleColor, x, y, stringFormatTitle);
}

【讨论】:

  • 谢谢先生。我还格式化了您的代码,使其更具可读性,但编辑没有通过..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-23
  • 2014-04-03
  • 1970-01-01
  • 2016-06-18
  • 2021-07-24
相关资源
最近更新 更多