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" onclick="tt();" />
</form>
</body>
</html>