频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

C#创建不规则窗体代码

来源:blog.csdn.net 作者:易庆华 出处:巧巧读书 2008-07-14 进入讨论组

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

进入讨论组讨论。
收藏此文】【 】【打印】【关闭
较早的文章:C#创建Windows服务

较新的文章:c# 实现远程关机
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章