C#的WinForms不规则的Windows [英] C# Winforms Irregular Windows

查看:107
本文介绍了C#的WinForms不规则的Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆