【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);
        }
    }
}
posted @ 2011-01-25 13:39  isaced  阅读(503)  评论(0编辑  收藏  举报