using System.Drawing;
using System;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
namespace Example006_设计多边形窗体
{
public partial class Form1:System.Windows.Forms.Form
{
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
[DllImport("gdi32")]
//创建一个多边形作为窗口的显示区域
private static extern IntPtr CreatePolygonRgn(Point[] lpPoint, int nCount, int nPolyFillMode);
//lpPoint:保存多边形顶点坐标的数组
//nCount:构成多边形的点数
//nPolyFillMode:填充方式
[DllImport("user32")]
//改变窗体形状
private static extern IntPtr SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
//hWnd:窗口句柄
//hRgn:显示区域的句柄
//bRedraw:是否重画窗体
private void Form1_Load(object sender, EventArgs e)
{
Point[] pt ={ new Point(this.Width/2,0),
new Point(0,this.Height/2),
new Point(this.Width/2,this.Height),
new Point(this.Width,this.Height/2),
new Point(this.Width,0)};
IntPtr m_rgn;
m_rgn = CreatePolygonRgn(pt,5,1);
SetWindowRgn(this.Handle, m_rgn, true);
}
}
}
多边形窗体(C#)
最新推荐文章于 2022-12-05 11:24:33 发布