C#创建不规则窗体代码(Win API应用)(转)

/* * ***********************警告********************************************

 * 如果引用请不要删除本注释!

 * 本代码受版权法和国际条约保护,如未经授权擅自复制或散发本代码(或其中任何部份),

 * 将受到严厉的法律制裁,并将在法律许可的最大限度内受到起诉!

 * 版权所有(C)  嘉怡工作室2000-2008

 * 公司:嘉怡工作室

 * 地址:湖南省岳阳县荣家湾镇城南村三组

 * 作者:易庆华先生

 * BLOG: http://yqh2648.blog.163.com.cn

 * E-Mail: yqh2648@163.com jiayistudio@163.com yqh2648@hotmail.com

 * Date:2008年

 * Runtime Version:.net 2.0

 * ************************************************************************/

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace APIDemo

{

    public partial class Form1 : Form

    {

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



      

        public Form1()

        {

            InitializeComponent();

            //创建不规则窗体

            POINTAPI[] poin;

            poin =new POINTAPI [5];

            poin[0].x = 90;

            poin[0].y = 90;

            poin[1].x = this.Width;

            poin[1].y = 0;

            poin[2].x = Width ;

            poin[2].y = this.Height/2;

            poin[3].x = Width / 2;

            poin[3].y = Height / 2;

            poin[4].x = 0;

            poin[4].y = Width;

            Boolean flag = true;

           IntPtr  hRgn= CreatePolygonRgn(ref poin[0],8,1);

           SetWindowRgn(this.Handle, hRgn, ref flag );

           this.BackColor = Color.BurlyWood;



        }

        //设置窗体显示状态

        [DllImport("user32.dll")]

        private static extern int SetWindowPos(

             IntPtr  hwnd,

             int hWndInsertAfter,

             int x,

             int y,

             int cx,

             int cy,

             int wFlags);





        private void Start_Btn_Click(object sender, EventArgs e)

        {//始终显示在前面

            SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1);

         

        }



     

        private void button1_Click(object sender, EventArgs e)

        {

            //最小化始终显示在前面

            SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 0);

        }

    }

}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值