c# - 为输入声明一个 Brushes 变量

标签 c# graphics colors bitmap

我目前有以下方法

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/

相关文章:

cocoa - 我需要将 NSImage 中的一个颜色 channel 归零,正确的方法是什么?

c# - 如何使用 Linq 实现 NextRcord 和 PreviousRecord 按钮?

c# - IOS 中的 AES 解密没有给出确切的结果

c# - Dispatcher.BeginInvoke c#,silverlight

graphics - Lua 2D 图形库的 Love2D 替代品

r - R 中多个变量的线图

iphone - 如何获取 UIView 中像素的颜色?

c# - Rx - 在新线程上消耗每个项目

c# - 在 C# 中放大条形码图像的最佳无损方法是什么

javascript - 使用 D3 根据背景更改文本颜色