声明用于输入的 Brushes 变量

the*_*age 1 c# graphics colors bitmap

我目前有以下方法

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

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

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

它会像这样使用:

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

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

Pra*_*ena 5

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

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

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

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