C# 的Brush 及相关颜色的操作

              // (实心刷)
                  Rectangle rect1 = new Rectangle(20, 80, 250, 100);
                 SolidBrush sbrush1 = new SolidBrush(Color.DarkOrchid);                  
                 SolidBrush sbrush2 = new SolidBrush(Color.Aquamarine);      
                  SolidBrush sbrush3 = new SolidBrush(Color.DarkOrange);

         //(梯度刷)
                  LinearGradientBrush lbrush1 = new LinearGradientBrush(rect1,
                  Color.DarkOrange, Color.Aquamarine,
                  LinearGradientMode.BackwardDiagonal);

                 //(阴影刷)
                 HatchBrush hbrush1 = new HatchBrush(HatchStyle.DiagonalCross,
                  Color.DarkOrange, Color.Aquamarine);
                  HatchBrush hbrush2 = new HatchBrush(HatchStyle.DarkVertical,
                  Color.DarkOrange, Color.Aquamarine);
                  HatchBrush hbrush3 = new HatchBrush(HatchStyle.LargeConfetti,
                  Color.DarkOrange, Color.Aquamarine);

                 //(纹理刷)
                  textureBrush = new TextureBrush(new Bitmap(@"e:\123.jpg"));
               
   //e.Graphics.FillRectangle(hbrush1, rect1);
                  //e.Graphics.FillRectangle(sbrush1, rect1);

     
             //e.Graphics.FillRectangle(textureBrush, rect1);
                  e.Graphics.FillRectangle(lbrush1, rect1);

------------------------------------

using System.Windows.Media;

1、String转换成Color

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

2、String转换成Brush

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

3、Color转换成Brush

            Brush brush = new SolidColorBrush(color));

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

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

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

(2)将Brush转成SolidColorBrush,再取Color。

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


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../../../JS/jquerycj/jquery-1.7.2.min.js" type="text/javascript"></script>
    <style>
        
    </style>
    <script>
        var s;
        var studata = [
            { id: 1, name: '张三', selected: true },
            { id: 2, name: '深蓝色', selected: true },
            { id: 3, name: '肖西林', selected: true },
            { id: 4, name: '田伟', selected: true },
            { id: 5, name: '李四', selected: true },
            { id: 6, name: '彭平', selected: false },
            { id: 7, name: '张三丰', selected: false },
            { id: 8, name: '肖西林', selected: false },
            { id: 9, name: '肖西林', selected: false },
            { id: 32, name: '肖西林', selected: false },
            { id: 22, name: '肖西林', selected: false },
            { id: 65, name: '肖西林', selected: false },
        ];
            $(function() {
                 s = new SelectStu('select_stubox',studata);
             });
            //取值
            function tt() {
                alert(s.val());
            }
    </script>
    <link href="http://localhost:12580/SOA/common/SelectStu/selectStu.css" rel="stylesheet" type="text/css" />
    <script src="http://localhost:12580/SOA/common/SelectStu/selectStu.js" type="text/javascript"></script>
</head>
<body>

    <form id="form1" runat="server">
    
   <div id = "select_stubox" style="width:600px;">
    </div>
    <input type="button" value="tt" οnclick="tt();" />
    </form>
</body>
</html>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值