1. 新建一个工程demo
2. 添加以下引用
using System.Runtime.InteropServices;[DllImport( " gdi32 " )] private static extern IntPtr CreatePolygonRgn(Point[] lpPoint, int nCount, int nPolyFillMode);[DllImport( " user32 " )] private static extern IntPtr SetWindowRgn(IntPtr hWnd,IntPtr hRgn, bool bRedraw); const int WINDING = 2 ;
3. 添加窗体的Load方法:
private void 设计多边形窗体_Load( object sender, System.EventArgs e) ... { Point[] pt=...{ new Point(this.Width /2,0), new Point(0,this.Height/2), new Point(this.Width/2,this.Height), new Point(this.Width,this.Height/2), new Point(this.Width,0) }; IntPtr m_rgn; m_rgn=CreatePolygonRgn(pt,5,WINDING); SetWindowRgn(this.Handle,m_rgn,true); } }