form1.cs
来自「csharp课本的源代码」· CS 代码 · 共 46 行
CS
46 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace PathGradientBrushExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Point centerPoint = new Point(80, 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.Red};
g.FillEllipse(brush, centerPoint.X - R, centerPoint.Y - R, 2 * R, 2 * R);
centerPoint = new Point(220, 80);
R = 20;
path = new GraphicsPath();
path.AddEllipse(centerPoint.X - R, centerPoint.Y - R, 2 * R, 2 * R);
path.AddEllipse(centerPoint.X - 2 * R, centerPoint.Y - 2 * R, 4 * R, 4 * R);
path.AddEllipse(centerPoint.X - 3 * R, centerPoint.Y - 3 * R, 6 * R, 6 * R);
brush = new PathGradientBrush(path);
brush.CenterPoint = centerPoint;
brush.CenterColor = Color.White ;
brush.SurroundColors = new Color[] { Color.Black, Color.Blue, Color.Green };
g.FillPath(brush, path);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?