我目前有以下方法
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("标题文本", Brushes.White);
但是,我认为在声明导致错误的 Brushes titleColor
时存在问题。
最佳答案
问题是您正在传递类型为 brush 的 Brushes.Color
的值,并且您的方法将 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);
}
关于c# - 为输入声明一个 Brushes 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21192097/