1.新建DownLayerForm的窗体。
2.定义不规则窗体的点,并在构造函数里面加载这些不规则的点。
3.效果如图所示。
private int layerWidth = 320; /// <summary> /// 消息框的宽度 /// </summary> public int LayerWidth { get { return layerWidth; } set { layerWidth = value; } } public DownLayerForm() { InitializeComponent(); //创建不规则窗体 POINTAPI[] poin; poin = new POINTAPI[7]; poin[0].x = 0; poin[0].y = 10; poin[1].x = layerWidth / 2 - 10; poin[1].y = 10; poin[2].x = layerWidth / 2; poin[2].y = 0; poin[3].x = layerWidth / 2 + 10; poin[3].y = 10; poin[4].x = layerWidth; poin[4].y = 10; poin[5].x = layerWidth; poin[5].y = 130; poin[6].x = 0; poin[6].y = 130; Boolean flag = true; IntPtr hRgn = CreatePolygonRgn(ref poin[0], 8, 1); SetWindowRgn(this.Handle, hRgn, ref flag); this.BackColor = Color.White; } [StructLayout(LayoutKind.Sequential)] private struct POINTAPI { internal int x; internal int y; } [DllImport("gdi32.dll")] private static extern IntPtr CreatePolygonRgn(ref POINTAPI lpPoint, int nCount, int nPolyFillMode); [DllImport("user32.dll")] private static extern IntPtr SetWindowRgn(IntPtr hWnd, IntPtr hRgn, ref Boolean bRedraw); //设置窗体显示状态 [DllImport("user32.dll")] private static extern int SetWindowPos(IntPtr hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
文章评论