想自已画一个矩形窗体,左上角和右上角都是圆角。
代码1:Graphics g=this.CreateGraphics();
g.Clear(this.BackColor);
Pen p=new Pen(Color.Blue,1);
int h=200;
int w=200;
int a=20;
int x=10;
int y=10;
g.DrawArc(p,x,y,a,a,180,90);
g.DrawLine(p,x+a/2,y,x+a/2+w,y);
g.DrawArc(p,x+w,y,a,a,270,90);
g.DrawLine(p,x+w+a,y+a/2,x+w+a,y+h+a);
g.DrawLine(p,x+w+a,y+h+a,x,y+h+a);
g.DrawLine(p,x,y+h+a,x,y+a/2);
p.Dispose();
g.Dispose();
这段代码是我用来测试,用代码画圆角矩形的一个测试例子.结果也正确。
代码2:protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
{
GraphicsPath shape=new GraphicsPath();
int w=this.Width;
int h=this.Height;
int a=20;
int x=0;
int y=0;
shape.AddArc(x,y,a,a,180,90);
shape.AddLine(x+a/2,y,x+a/2+w,y);
shape.AddArc(x+w,y,a,a,270,90);
shape.AddLine(x+w+a,y+a/2,x+w+a,y+h+a);
shape.AddLine(x+w+a,y+h+a,x,y+h+a);
shape.AddLine(x,y+h+a,x,y+a/2);
this.Region = new System.Drawing.Region(shape);
}
代码2中的代码几乎就是代码1中的代码,只是很小的区别。但是得到的窗体只有左上角变成了圆角,右上角没有任何变化。郁闷!~~~~哪位达人帮忙看一下!~谢谢~!~分不够的话可以再加。
代码1:Graphics g=this.CreateGraphics();
g.Clear(this.BackColor);
Pen p=new Pen(Color.Blue,1);
int h=200;
int w=200;
int a=20;
int x=10;
int y=10;
g.DrawArc(p,x,y,a,a,180,90);
g.DrawLine(p,x+a/2,y,x+a/2+w,y);
g.DrawArc(p,x+w,y,a,a,270,90);
g.DrawLine(p,x+w+a,y+a/2,x+w+a,y+h+a);
g.DrawLine(p,x+w+a,y+h+a,x,y+h+a);
g.DrawLine(p,x,y+h+a,x,y+a/2);
p.Dispose();
g.Dispose();
这段代码是我用来测试,用代码画圆角矩形的一个测试例子.结果也正确。
代码2:protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
{
GraphicsPath shape=new GraphicsPath();
int w=this.Width;
int h=this.Height;
int a=20;
int x=0;
int y=0;
shape.AddArc(x,y,a,a,180,90);
shape.AddLine(x+a/2,y,x+a/2+w,y);
shape.AddArc(x+w,y,a,a,270,90);
shape.AddLine(x+w+a,y+a/2,x+w+a,y+h+a);
shape.AddLine(x+w+a,y+h+a,x,y+h+a);
shape.AddLine(x,y+h+a,x,y+a/2);
this.Region = new System.Drawing.Region(shape);
}
代码2中的代码几乎就是代码1中的代码,只是很小的区别。但是得到的窗体只有左上角变成了圆角,右上角没有任何变化。郁闷!~~~~哪位达人帮忙看一下!~谢谢~!~分不够的话可以再加。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货