程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#創建不規則窗體代碼

C#創建不規則窗體代碼

編輯:關於C語言
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);
        }
      }
    }
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved