软件频道>程序开发>JavaVBVCDelphiC/C++Web开发微软专栏移动数据库程序人生软件工程|开发客
您现在的位置: 天极网 > 开发频道 > C#创建不规则窗体
全文

C#创建不规则窗体

2008-07-16 10:36作者:wyhjianhw出处:天极网责任编辑:nancy

  我们常见的窗体都是规则的,那么如何用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);
  }
  }
  }

相关搜索:
关注此文读者还看过
热门关注
特别推荐
文章排行
本周
本月
最近更新
关于我们|About us|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2009 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 渝ICP证B2-20030003号
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众