class PicClass:PictureBox
{
public PicClass()
{
this.SetStyle(ControlStyles.ResizeRedraw, true);//空间大小改变时,控件会重绘
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Graphics graphics = pe.Graphics ;//一定不要使用this.createGraphics
graphics.Clear(Color.White );
GraphicsPath graphicsPath = new GraphicsPath();
graphicsPath.AddEllipse(new Rectangle (30,30,50,50));
Region oldElip = graphics.Clip;
graphics.Clip = new Region(graphicsPath);
graphics.DrawImage(this.Image, new Rectangle(0, 0, this.Width , this.Height ) );
graphics.Clip = oldElip;//剪辑区域还原
}