using System.Drawing.Drawing2D; protected override void OnPaint( System.Windows.Forms.PaintEventArgs e ) { GraphicsPath oPath = new GraphicsPath(); int x=0; int y=0; int w=Width; int h=Height; int a=40; Graphics g=CreateGraphics(); oPath.AddArc(x,y,a,a,180,90); oPath.AddArc(w-a,y,a,a,270,90); oPath.AddArc(w-a/2,h-a/2,a/2,a/2,0,90); oPath.AddArc(x,h-a,a,a,90,90); oPath.CloseAllFigures(); Region=new Region(oPath); }
protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
{
GraphicsPath oPath = new GraphicsPath();
int x=0;
int y=0;
int w=Width;
int h=Height;
int a=40;
Graphics g=CreateGraphics();
oPath.AddArc(x,y,a,a,180,90);
oPath.AddArc(w-a,y,a,a,270,90);
oPath.AddArc(w-a/2,h-a/2,a/2,a/2,0,90);
oPath.AddArc(x,h-a,a,a,90,90);
oPath.CloseAllFigures();
Region=new Region(oPath);
}
又学会一样东西.
但我想知道怎样在Graphics加入方法
public void DrawRoundRect(Pen pen,int x,int y,int width,int height,int arcHeight,int arcWidth)
{
GraphicsPath gp=new GraphicsPath();
gp.AddArc(x,y,arcWidth,arcWidth,180,90);
gp.AddArc(width-arcWidth,y,arcWidth,arcWidth,270,90);
gp.AddArc(width -arcWidth,height-arcWidth,arcWidth,arcWidth,0,90);
gp.AddArc(x,height-arcWidth,arcWidth,arcWidth,90,90);
gp.CloseAllFigures();
return gp;
}这对你的要求的函数进行了一些修改。返回值是一个GraphicsPath。同时,你的要求是的圆角其实是椭圆,我简化成了正圆。你可以在上面代码的基础上改成椭圆。但要改的不仅仅是arcWidth一个参数。还要修改后面的角度(有点麻烦)。