public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius){    GraphicsPath gp=new GraphicsPath();    gp.AddLine(X + radius, Y, X + width - (radius*2), Y);    gp.AddArc(X + width - (radius*2), Y, radius*2, radius*2, 270, 90);    gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius*2));    gp.AddArc(X + width - (radius*2), Y + height - (radius*2), radius*2, radius*2,0,90);    gp.AddLine(X + width - (radius*2), Y + height, X + radius, Y + height);    gp.AddArc(X, Y + height - (radius*2), radius*2, radius*2, 90, 90);    gp.AddLine(X, Y + height - (radius*2), X, Y + radius);    gp.AddArc(X, Y, radius*2, radius*2, 180, 90);    gp.CloseFigure();    g.DrawPath(p, gp);
    gp.Dispose();
}

解决方案 »

  1.   

    [DllImport("gdi32.Dll")]
    public static extern int CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
      

  2.   

    谢谢
    可在CSDN中写着:
    GDI 提供几种用于创建区域的函数:CreateRectRgn、CreateEllpticRgn、CreateRoundRectRgn、CreatePolygonRgn 和 CreatePolyPolygonRgn。您或许希望 GDI+ 中的 Region 类也有类似的构造函数,将矩形、椭圆、圆角矩形和多边形作为参数接收,但事实并非如此。GDI+ 中的 Region 类提供一个接收 Rectangle 对象的构造函数和另一个接收 GraphicsPath 对象的构造函数。如果您想基于椭圆、圆角矩形或多边形构造区域,可以通过创建一个 GraphicsPath 对象(例如包含椭圆的对象),然后将其传递至 Region 构造函数来轻松实现。
    我想知道这里说的使用GraphicsPath就是用
    GraphicsPath.gp.AddLine
    GraphicsPath.gp.AddArc
    吗?
    如果这样那还是用API好了。
      

  3.   


    Setting the control region
    Everybody who used Windows XP has very probably noticed that buttons have rounded corners. The graphic shape of the button looks like this:So, we'll create such a region (the interior of a graphics shape) for our button.int X = this.Width; 
    int Y = this.Height;  
    Point[] points = {    new Point(1, 0), 
                          new Point(X-1, 0), 
                          new Point(X-1, 1), 
                          new Point(X, 1), 
                          new Point(X, Y-1), 
                          new Point(X-1, Y-1), 
                          new Point(X-1, Y), 
                          new Point(1, Y), 
                          new Point(1, Y-1), 
                          new Point(0, Y-1), 
                          new Point(0, 1), 
                          new Point(1, 1)}    
    GraphicsPath path = new GraphicsPath();
    path.AddLines(points);
    this.Region = new Region(path);
      

  4.   

    Thank u ,BearRui
    i get it,that's just what i fond