C#Winforms不规则窗口

C#Winforms不规则窗口,c#,windows,winforms,C#,Windows,Winforms,如何使用WinForms和C#创建具有不规则形状的窗口?有几种不同的方法可以实现这一点。一种是使用透明密钥(正如Nifle在文章中指出的)。另一种方法是将对象指定给窗体的属性: System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddPolygon(new[] { new Point(20, 20), new Point(40, 10),

如何使用WinForms和C#创建具有不规则形状的窗口?

有几种不同的方法可以实现这一点。一种是使用透明密钥(正如Nifle在文章中指出的)。另一种方法是将对象指定给窗体的属性:

System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddPolygon(new[]
{
    new Point(20, 20),
    new Point(40, 10),
    new Point(180, 70),
    new Point(160, 260),
    new Point(80, 140)
});
path.AddEllipse(40, 40, 300, 300);
this.Region = new Region(path);

请注意,坐标指的是窗口,而不是客户区。另外请注意,默认情况下,
GraphicsPath
对象中的重叠图形是如何相互“反转”的(这可以通过设置
path.FillMode=FillMode.Winding
)来防止)。您对不规则图形的定义是什么?我猜没有标题栏、边框、,等等?没有像我们看到的一些windows media player外壳那样的不规则窗口,得到的点不是矩形或圆形边缘。这应该是闭合的,因为这是一个像尖头一样的复制。