【C#】[窗体]不规则窗体

效果图:          (源码下载

【C#】[窗体]不规则窗体

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;//



namespace 不规则窗体

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        

        //---------------------



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



        private void Form1_Load(object sender, EventArgs e)

        {

            Point[] pt ={

                            new Point(0,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);

        }

    }

}

你可能感兴趣的:(C#)