您的足迹:首页 > 未分类 >用Winform绘制不规则矩形

用Winform绘制不规则矩形

QQ截图20160905113344.png

 

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);

 

本博客所有文章如无特别注明均为原创。作者:cc复制或转载请以超链接形式注明转自 我的博客
原文地址《用Winform绘制不规则矩形

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)