C#利用GDI+绘制由中心向四周渐变的图形
private void Draw(IntPtr winHandle,Point location,Size size)
{
Graphics g = Graphics.FromHwnd(winHandle);
GraphicsPath gp = new GraphicsPath();
Rectangle rec = new Rectangle(location, size);
gp.AddRectangle(rec);
Color[] surroundColor = new Color[] { Color.White };
PathGradientBrush pb = new PathGradientBrush(gp);
pb.CenterColor = Color.Green;
pb.SurroundColors = surroundColor;
g.FillPath(pb, gp);
}
// 测试
private void btnTest_Click(object sender, EventArgs e)
{
Draw(pictureBox1.Handle, new Point(10, 10),new Size( 20, 20));
}