我想实现一个有三种颜色的线形渐变,代码如下:
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point( 0 , 0 ) , this.Size ) , System.Drawing.Color.Red
, Color.Yellow , System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend(3);
colorBlend.Colors[0] = Color.Green;
colorBlend.Colors[1] = Color.Yellow;
colorBlend.Colors[2] = Color.Red;
colorBlend.Positions[0] = 0.0f;
colorBlend.Positions[1] = 0.3f;
colorBlend.Positions[2] = 1.0f;
brush.InterpolationColors = colorBlend;
System.Drawing.Drawing2D.Blend blend = new System.Drawing.Drawing2D.Blend(3);
blend.Factors[0] = 0.0f;
blend.Positions[0] = 0.0f;
blend.Factors[1] = 0.7f;
blend.Positions[1] = 0.1f;
blend.Factors[2] = 1f;
blend.Positions[2] = 1f;
brush.Blend = blend;
g.FillRectangle(brush , 1 , 1 , this.Size.Width , this.Size.Height);
但是出来的还是两个颜色,各位高手帮看看,是那个地方的问题。
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point( 0 , 0 ) , this.Size ) , System.Drawing.Color.Red
, Color.Yellow , System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend(3);
colorBlend.Colors[0] = Color.Green;
colorBlend.Colors[1] = Color.Yellow;
colorBlend.Colors[2] = Color.Red;
colorBlend.Positions[0] = 0.0f;
colorBlend.Positions[1] = 0.3f;
colorBlend.Positions[2] = 1.0f;
brush.InterpolationColors = colorBlend;
System.Drawing.Drawing2D.Blend blend = new System.Drawing.Drawing2D.Blend(3);
blend.Factors[0] = 0.0f;
blend.Positions[0] = 0.0f;
blend.Factors[1] = 0.7f;
blend.Positions[1] = 0.1f;
blend.Factors[2] = 1f;
blend.Positions[2] = 1f;
brush.Blend = blend;
g.FillRectangle(brush , 1 , 1 , this.Size.Width , this.Size.Height);
但是出来的还是两个颜色,各位高手帮看看,是那个地方的问题。
解决方案 »
- datagridview 中的值不能更新
- 又发现一个DataGirdView的Bug..
- c# 如何获取指定位数的md5加密密文,因为默认得到16位或32位的密文,我想得到8位或任意行不行,请高手帮忙啊?
- 关于多线程的小问题
- OracleDataAdapter 更新数据出错
- X,Y点阵的实时曲线问题,请教大侠
- datagrid问题,某行可以选择
- 请问:怎样往IE里添加自定义的工具条(像Google Toolbar,MSN Toolbar那样的)?
- C#程序无法在win2000下运行的问题
- 如何旋转控件
- 如何将stream 转化为string,谢谢
- 多线程传OleDbDataReader变量的问题 ?
blend.Positions[1] = 0.2f;