2010-04-19 31 views
3

我正在使用下面的代码来改变形状的winform。 它改变了形状,但不像我想要的。 我需要的形式有弯曲的角落。如何制作非矩形Winforms?

我应该使用什么来得到它?

public void MakeNonRectangularForm() 
    { 
     System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath(); 
     int width = this.ClientSize.Width; 
     int height = this.ClientSize.Height; 
     p.AddClosedCurve(new Point[]{new Point(width/2, height/2), 
      new Point(width,0), new Point(width, height/3), 
      new Point(width-width/3, height), 
      new Point(width/7, height-height/8)}); 
     this.Region = new Region(p); 
    } 

回答

2

下面是一些代码,我已经使用之前创建圆边,使用AddArc和线条拼凑出边界:

(你可以用xRadiusyRadius发挥,以达到所需的“量圆形“)

int xRadius = {insert value here}; 
int yRadius = {insert value here}; 

GraphicsPath edge = new GraphicsPath(); 

int rightHandLeft = this.Width - xRadius - 1; 
int bottomSideTop = this.Height - yRadius - 1; 

edge.AddArc(0, 0, xRadius, yRadius, 180, 90); 
edge.AddLine(xRadius, 0, rightHandLeft, 0); 

edge.AddArc(rightHandLeft, 0, xRadius, yRadius, 270, 90); 
edge.AddLine(this.Width, yRadius, this.Width, bottomSideTop); 

edge.AddArc(rightHandLeft, bottomSideTop, xRadius, yRadius, 0, 90); 
edge.AddLine(rightHandLeft, this.Height, xRadius, this.Height); 

edge.AddArc(0, bottomSideTop, xRadius, yRadius, 90, 90); 
edge.AddLine(0, bottomSideTop, 0, yRadius); 

this.Region = new Region(edge);