我该如何使用WinForms和C#创建具有不规则形状的窗口?
TransparencyKey
(如 Nifle 指出的帖子中所示)。另一种方法是将 Region
对象分配给窗体的 Region
属性: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
来防止这种情况发生)。