使用PathGradientBrush类

来源:互联网 发布:matlab数组写入excel 编辑:程序博客网 时间:2024/06/05 03:45
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Point centerPoint = new Point(160, 80);
            int R = 60;
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(centerPoint.X - R, centerPoint.Y - R, 2 * R, 2 * R);
            PathGradientBrush brush = new PathGradientBrush(path);
            //指定路径中心点
            brush.CenterPoint = centerPoint;
            //指定路径中心点的颜色
            brush.CenterColor = Color.White;
            //Color类型的数组指定与路径上每个顶点对应的颜色
            brush.SurroundColors = new Color[] { Color.Black };
            g.FillEllipse(brush, centerPoint.X - R, centerPoint.Y - R, 2 * R, 2 * R);


        }
    }
}
原创粉丝点击