C#中Brush、Color、String相互转换

1String转换成Color

            Color color = (Color)ColorConverter.ConvertFromString(string);

2String转换成Brush

            BrushConverter brushConverter = new BrushConverter();
            Brush brush = (Brush)brushConverter.ConvertFromString(string);

3Color转换成Brush

            Brush brush = new SolidColorBrush(color));

4Brush转换成Color有两种方法:

1)先将Brush转成string,再转成Color

            Color color= (Color)ColorConverter.ConvertFromString(brush.ToString());

2)将Brush转成SolidColorBrush,再取Color

            Color color= ((SolidColorBrush)CadColor.Background).Color;

posted @ 2012-06-27 14:26  90后1场梦  阅读(801)  评论(0编辑  收藏  举报