c#form控件渐变色源代码

c#控件渐变色源代码
在winform 控件实际使用过程中,有时候我们为了好看,会使控件北京颜色显示为渐变设,
这个时候我们需要重写Paint 控件, 下面以panel 为例,核心方法:g.FillRectangle(b, this.ClientRectangle);
源代码如下:

using System.Drawing;
using System.Drawing.Drawing2D;
///
/// 渐变色
///
///
///
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Color FColor = Color.MintCream;
Color TColor = Color.PaleTurquoise;
//实例化刷子,第一个参数指示上色区域,第二个和第三个参数分别渐变颜色的开始和结束,第四个参数表示颜色的方向。
Brush b = new LinearGradientBrush(this.ClientRectangle, FColor, TColor, LinearGradientMode.Horizontal); //从左到右渐变色
// Brush b = new LinearGradientBrush(this.ClientRectangle, FColor, TColor, LinearGradientMode.Vertical); //从上到下渐变色
g.FillRectangle(b, this.ClientRectangle); //进行上色
}

效果如下:

http://www.51jrft.com/jlmb/Others/23994.html

原文链接:http://www.51jrft.com/jlmb/Others/23994.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值