Convert string to Color in C#

后端 未结 10 1292
我寻月下人不归
我寻月下人不归 2020-11-29 07:03

I am encountering a problem which is how do I convert input strings like \"RED\" to the actual Color type Color.Red in C#. Is there a good way to do this?

10条回答
  •  抹茶落季
    2020-11-29 07:34

    For transferring colors via xml-strings I've found out:

    Color x = Color.Red; // for example
    String s = x.ToArgb().ToString()
    ... to/from xml ...
    Int32 argb = Convert.ToInt32(s);
    Color red = Color.FromArgb(argb);
    

提交回复
热议问题