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 Gid_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
{
int span = ;
//抗锯齿
g.SmoothingMode = SmoothingMode.AntiAlias;
//渐变填充
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
//画尖角
if (cusp)
{
span = ;
PointF p1 = new PointF(rectangle.Width - , rectangle.Y + );
PointF p2 = new PointF(rectangle.Width - , rectangle.Y + );
PointF p3 = new PointF(rectangle.Width, rectangle.Y + );
PointF[] ptsArray = { p1, p2, p3 };
g.FillPolygon(myLinearGradientBrush, ptsArray);
}
//填充
g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height-, _radius));
}
public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
{
//四边圆角
GraphicsPath gp = new GraphicsPath();
gp.AddArc(x, y, radius, radius, , );
gp.AddArc(width - radius, y, radius, radius, , );
gp.AddArc(width - radius, height - radius, radius, radius, , );
gp.AddArc(x, height - radius, radius, radius, , );
gp.CloseAllFigures();
return gp;
} private void panel1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, ,true, Color.FromArgb(, , ), Color.FromArgb(, , ));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个Panel", new Font("微软雅黑", , FontStyle.Regular), new SolidBrush(Color.White), new PointF(, ));
} private void panel2_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, , false, Color.FromArgb(, , ), Color.FromArgb(, , ));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个Panel", new Font("微软雅黑", , FontStyle.Regular), new SolidBrush(Color.White), new PointF(, ));
} private void button1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, , false, Color.FromArgb(, , ), Color.FromArgb(, , ));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("其实我是个按钮", new Font("微软雅黑", , FontStyle.Regular), new SolidBrush(Color.White), new PointF(, ));
} private void label1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, , false, Color.FromArgb(, , ), Color.FromArgb(, , ));
base.OnPaint(e); Graphics g = e.Graphics;
g.DrawString("其实我是Label", new Font("微软雅黑", , FontStyle.Regular), new SolidBrush(Color.Black), new PointF(, ));
}
}
}