c#中怎样用shape显示由不同颜色组成的色条
2个回答
2014-12-26
展开全部
Shape shape = new Rectangle();
shape.Width = 25;
shape.Height = 200;
var linearGradientBrush = new LinearGradientBrush();
linearGradientBrush.StartPoint = new Point(0.5, 0);
linearGradientBrush.EndPoint = new Point(0.5, 1);
var random = new Random();
for (int i = 0; i < 100; i++)
{
var color = new Color();
color.A = byte.MaxValue;
color.R = (byte)random.Next(0, byte.MaxValue + 1);
color.G = (byte)random.Next(0, byte.MaxValue + 1);
color.B = (byte)random.Next(0, byte.MaxValue + 1);
var gradientStop = new GradientStop();
gradientStop.Color = color;
gradientStop.Offset = 0.01 * i;
linearGradientBrush.GradientStops.Add(gradientStop);
}
shape.Fill = linearGradientBrush;
this.MainGrid.Children.Add(shape);
这样么?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询