问题描述
如何创建使用WinForms和C#不规则形状的窗口?
How do I create windows with irregular shapes using WinForms and C#?
推荐答案
有几种不同的方式来实现这一目标。一种是使用使用 TransparencyKey
(如在后所指出的Nifle)。另一种是将分配一个反对的形式的属性:
There are a few different ways to achieve this. One is use use TransparencyKey
(as in the post pointed out by Nifle). Another one is to assign a Region
object to the Region
property of the form:
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
)。
Note that the coordinates refer to the window, not the client area. Also note how overlapping figures in the GraphicsPath
object "invert" each other by default (this can be prevented by setting path.FillMode = FillMode.Winding
).
这篇关于C#的WinForms不规则的Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!