用渐变色填充区域

用渐变色填充区域

 

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;

namespace 渐变
{
    
/// <summary>
    
/// Form1 的摘要说明。
    
/// </summary>

    public class Form1 : System.Windows.Forms.Form
    
{
        
/// <summary>
        
/// 必需的设计器变量。
        
/// </summary>

        private System.ComponentModel.Container components = null;

        
public Form1()
        
{
            
//
            
// Windows 窗体设计器支持所必需的
            
//
            InitializeComponent();

            
//
            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            
//
        }


        
/// <summary>
        
/// 清理所有正在使用的资源。
        
/// </summary>

        protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if (components != null
                
{
                    components.Dispose();
                }

            }

            
base.Dispose( disposing );
        }


        
Windows Form Designer generated code

        
/// <summary>
        
/// 应用程序的主入口点。
        
/// </summary>

        [STAThread]
        
static void Main() 
        
{
            Application.Run(
new Form1());
        }


        
protected override void OnPaint(PaintEventArgs e)
        
{
            Graphics g
=e.Graphics;
            
//定义一个线性梯度刷
            LinearGradientBrush lGBrush=new LinearGradientBrush( 
                
new Point(010), 
                
new Point(15010),
                Color.FromArgb(
25525500),
                Color.FromArgb(
25502550));
            Pen pen
=new Pen(lGBrush);
            
//用线性梯度刷效果的笔绘制一条直线段,填充一个矩形
            g.DrawLine(pen, 10130500130);
            g.FillRectangle(lGBrush, 
5015037030);

            
//定义路径并添加一个椭圆
            GraphicsPath gp=new GraphicsPath();
            gp.AddEllipse(
1010200100);
            
//用该路径定义路径梯度刷
            PathGradientBrush brush=new PathGradientBrush(gp);
            
//颜色数组
            Color[] colors= {
                    Color.FromArgb(
25525500),
                    Color.FromArgb(
255100100100),
                    Color.FromArgb(
25502550),
                    Color.FromArgb(
25500255)}
;
            
//定义颜色渐变比率
            float[] r = {
                    
0.0F,
                    
0.3F,
                    
0.6F,
                    
1.0F}
;
            ColorBlend blend
=new ColorBlend();
            blend.Colors 
= colors;
            blend.Positions 
= r;
            brush.InterpolationColors 
= blend;
            
//在椭圆外填充一个矩形
            g.FillRectangle(brush, 00210110);

            
//用添加了椭圆的路径定义第二个路径梯度刷
            GraphicsPath gp2=new GraphicsPath();
            gp2.AddEllipse(
3000200100);
            PathGradientBrush brush2
=new PathGradientBrush(gp2);
            
//设置中心点的位置和颜色
            brush2.CenterPoint = new PointF(45050);
            brush2.CenterColor 
= Color.FromArgb(25502550);
            
//设置边界颜色
            Color[] colors2 = {Color.FromArgb(25525500)};
            brush2.SurroundColors 
= colors2;
            
//用第二个梯度刷填充椭圆
            g.FillEllipse(brush2, 3000200100);
        }

    }

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值