Windows窗体"孔"

cam*_*cam 5 c# forms graphics

我如何在Windows窗体中创建一个动态的"洞",用户可以通过它看到实际的桌面而不是窗体?现在我已经在整个屏幕上创建了一个半透明的表单,我希望透过这个半透明的表单.

Sim*_*mon 10

使用表单的Region属性.

Rectangle rect = new Rectangle(Point.Empty, this.Size);
Region region = new Region(rect);

rect.Inflate(-1 * (this.Width / 3), -1 * (this.Height / 3));
region.Exclude(rect);

this.Region = region;
Run Code Online (Sandbox Code Playgroud)

这应该会在你的表格中留下一个漏洞.


Reg*_*ent 5

作为替代方案,如果您需要矩形形式的“孔”,您可以将表单的TransparencyKey属性设置为某种颜色,然后创建一个具有相同颜色背景的面板。(该面板在运行时将是透明的。)