<分区>
如何使用 WinForms 和 C# 创建不规则形状的窗口?
<分区>
如何使用 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
来防止)。
关于C# Winforms 不规则窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1326673/