Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有
public String colorid = "Blue";
和
Sbrush = new SolidBrush(Color.Convert.ToInt32(colorid));
我希望能够在其他地方定义 colorid,这就是我这样编写 SolidBrush 代码的原因。现在这不起作用,如果有人可以帮助我,我将不胜感激
使用从名称创建颜色
Color.FromName("Blue")
这种方式同时支持颜色名称和 html 颜色:
string nm = "Blue"; // or f.ex. "#0000ff" if (nm.StartsWith("#")) { return ColorTranslator.FromHtml(nm); } else { return Color.FromName(nm); }