电脑软硬件应用网
当前位置: 电脑软硬件应用网 > 设计学院 > 网络编程 > C语言 > 正文
C#创建不规则窗体代码
C#创建不规则窗体代码
2008-7-21 23:17:25  文/转载未知   出处:电脑软硬件应用网   

         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语言实现的闹钟程序
    C#实现Windows关机的代码
    用动态规划法求组和数的算法
    循环结构程序具有哪3个组成部分?
    const成员函数有什么特点?
    c语言求平均分程序
    一道关于指针的C语言题
    C语言求3个整数的最大公约数
    BM模式匹配算法C语言实现
    从键盘输入任意5个4位整数存入数组a…
    关于45IT | About 45IT | 联系方式 | 版权声明 | 网站导航 |

    Copyright © 2003-2011 45IT. All Rights Reserved 浙ICP备09049068号