高级绘图
转载原文。改写绘图高级功能
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace 控件模拟别人的

{
public partial class Form1 : Form
{
private RectangleF selectorRct = Rectangle.Empty;
private int opacity = 200;
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
//e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
//DrawSelector(e);
}
private void DrawSelector(PaintEventArgs e)
{
selectorRct.X = this.Width/2;
selectorRct.Y = this.Height/2;
GraphicsPath gp = CreateRoundedRectangle(selectorRct, 100);
Pen p=new Pen(Color.FromArgb(200,Color .Black));
e.Graphics .DrawPath(p,gp);
PathGradientBrush pgb=new PathGradientBrush(gp);

Color[] surroundColor = new Color[]
{
Color.FromArgb(opacity, 227, 243, 255),
Color.FromArgb(opacity, 189, 205, 233),
Color.FromArgb(opacity, 103, 150, 161),
Color.FromArgb(opacity, 76, 118, 146)};
float[] positions = new float[]
{ 0f, .82f, .85f, 1.0f };
ColorBlend blnd = new ColorBlend();
blnd.Positions = positions;
blnd.Colors = surroundColor;
pgb.InterpolationColors = blnd;
pgb.SurroundColors = surroundColor;
e.Graphics.FillPath(pgb, gp);
p.Dispose();
gp.Dispose();
pgb.Dispose();
}
public static GraphicsPath CreateRoundedRectangle(RectangleF rct, int radius)
{
GraphicsPath gp = new GraphicsPath();
PointF pt1 = new PointF(rct.X + radius, rct.Y);
PointF pt2 = new PointF(rct.X + rct.Width - radius, rct.Y);
RectangleF rct1 = new RectangleF(rct.X, rct.Y, radius, radius);
gp.AddArc(rct1, 180f, 90f);
gp.AddLine(pt1, pt2);
rct1.Location = pt2;
gp.AddArc(rct1, 270f, 90f);
pt1 = new PointF(rct.X + rct.Width, rct.Y + radius);
pt2 = new PointF(rct.X + rct.Width, rct.Y + rct.Height - radius);
gp.AddLine(pt1, pt2);
rct1.Location = new PointF(rct.X + rct.Width - radius, rct.Y + rct.Height - radius);
gp.AddArc(rct1, 0f, 90f);
pt1 = new PointF(rct.X + rct.Width - radius, rct.Y + rct.Height);
pt2 = new PointF(rct.X + radius, rct.Y + rct.Height);
gp.AddLine(pt1, pt2);
rct1.Location = new PointF(rct.X, rct.Y + rct.Height - radius);
gp.AddArc(rct1, 90f, 90f);
gp.CloseFigure();
return gp;
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
DrawSelector(e);
//panel1.Refresh();
}
}
}
浙公网安备 33010602011771号