WinForm中窗体重画成圆角矩形

 

private Image img=null;//声明字段

------------------------------

public frmLogin()
  {
   img=new Bitmap(@"img/Login.jpg");-//构造函数中定义图片
   oldp=new Point(0,0);
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

 

---------------------------------

//核心代码,在窗体的Paint事件中重新画窗体

GraphicsPath gp=new GraphicsPath();
   //topleft
   Point p1=new Point(0,10);
   Point p2=new Point(2,4);
   Point p3=new Point(4,2);
   Point p4=new Point(10,0);
   Point[] lpp={p1,p2,p3,p4};
   gp.AddCurve(lpp);
   p1.X=10;p1.Y=0;
   p2.X=0;p2.Y=0;
   p3.X=0;p3.Y=10;
   Point[] lppp={p1,p2,p3};
   gp.AddLines(lppp);

   //topRight
   p1.X=300;p1.Y=10;
   p2.X=298;p2.Y=4;
   p3.X=296;p3.Y=2;
   p4.X=290;p4.Y=0;
   Point[] rpp={p1,p2,p3,p4};
   gp.AddCurve(rpp);
   p1.X=290;p1.Y=0;
   p2.X=300;p2.Y=0;
   p3.X=300;p3.Y=10;
   Point[] rppp={p1,p2,p3};
   gp.AddLines(rppp);

   //endleft
   p1.X=0;p1.Y=190;
   p2.X=2;p2.Y=196;
   p3.X=4;p3.Y=198;
   p4.X=10;p4.Y=200;
   Point[] elpp={p1,p2,p3,p4};
   //gp.ClearMarkers();
   GraphicsPath egp=new GraphicsPath();
   egp.AddCurve(elpp);
   p1.X=10;p1.Y=200;
   p2.X=0;p2.Y=200;
   p3.X=0;p3.Y=190;
   Point[] elppp={p1,p2,p3};
   egp.AddLines(elppp);

   //endRight
   p1.X=300;p1.Y=190;
   p2.X=298;p2.Y=196;
   p3.X=296;p3.Y=198;
   p4.X=290;p4.Y=200;
   Point[] erpp={p1,p2,p3,p4};
   egp.AddCurve(erpp);
   p1.X=290;p1.Y=200;
   p2.X=300;p2.Y=200;
   p3.X=300;p3.Y=190;
   Point[] erppp={p1,p2,p3};
   egp.AddLines(erppp);

   //重新画
   Region rr=new Region(gp);
   Region err=new Region(egp);
   e.Graphics.ExcludeClip(rr);
   e.Graphics.ExcludeClip(err);
   e.Graphics.DrawImage(img,0,0,300,200);
   e.Graphics.ResetClip();   
                                                                                                      --阿东研究

posted @ 2006-04-05 09:50  阿东工作室  阅读(981)  评论(1编辑  收藏  举报