几何尺寸与公差论坛

 找回密码
 注册
查看: 405|回复: 0

wpf 实现渐变颜色值,用c#编写

[复制链接]
发表于 2023-4-7 15:40:18 | 显示全部楼层 |阅读模式
在WPF中,您可以使用LinearGradientBrush或RadialGradientBrush来创建渐变颜色。这些画笔可以用作填充或描边的画笔,以创建具有渐变颜色的形状或控件。

例如,以下代码创建了一个具有线性渐变填充的矩形:

Rectangle rect = new Rectangle();
rect.Width = 200;
rect.Height = 100;

LinearGradientBrush brush = new LinearGradientBrush();
brush.StartPoint = new Point(0, 0);
brush.EndPoint = new Point(1, 1);

GradientStop stop1 = new GradientStop(Colors.Red, 0.0);
GradientStop stop2 = new GradientStop(Colors.Yellow, 0.5);
GradientStop stop3 = new GradientStop(Colors.Blue, 1.0);

brush.GradientStops.Add(stop1);
brush.GradientStops.Add(stop2);
brush.GradientStops.Add(stop3);

rect.Fill = brush;
上面的代码创建了一个宽度为200,高度为100的矩形,并使用线性渐变画笔进行填充。渐变画笔从左上角开始,到右下角结束,并包含三个渐变停靠点:红色(偏移量为0.0),黄色(偏移量为0.5)和蓝色(偏移量为1.0)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-5-9 13:00 , Processed in 0.081255 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表