当前位置:   article > 正文

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

c# brushes
              // (实心刷)
                  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;


  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head id="Head1" runat="server">
  3. <title></title>
  4. <script src="../../../JS/jquerycj/jquery-1.7.2.min.js" type="text/javascript"></script>
  5. <style>
  6. </style>
  7. <script>
  8. var s;
  9. var studata = [
  10. { id: 1, name: '张三', selected: true },
  11. { id: 2, name: '深蓝色', selected: true },
  12. { id: 3, name: '肖西林', selected: true },
  13. { id: 4, name: '田伟', selected: true },
  14. { id: 5, name: '李四', selected: true },
  15. { id: 6, name: '彭平', selected: false },
  16. { id: 7, name: '张三丰', selected: false },
  17. { id: 8, name: '肖西林', selected: false },
  18. { id: 9, name: '肖西林', selected: false },
  19. { id: 32, name: '肖西林', selected: false },
  20. { id: 22, name: '肖西林', selected: false },
  21. { id: 65, name: '肖西林', selected: false },
  22. ];
  23. $(function() {
  24. s = new SelectStu('select_stubox',studata);
  25. });
  26. //取值
  27. function tt() {
  28. alert(s.val());
  29. }
  30. </script>
  31. <link href="http://localhost:12580/SOA/common/SelectStu/selectStu.css" rel="stylesheet" type="text/css" />
  32. <script src="http://localhost:12580/SOA/common/SelectStu/selectStu.js" type="text/javascript"></script>
  33. </head>
  34. <body>
  35. <form id="form1" runat="server">
  36. <div id = "select_stubox" style="width:600px;">
  37. </div>
  38. <input type="button" value="tt" οnclick="tt();" />
  39. </form>
  40. </body>
  41. </html>




声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/773849
推荐阅读
相关标签
  

闽ICP备14008679号