不规则形状的 Windows 窗体 (C#)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/176720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:43:35  来源:igfitidea点击:

Irregular shaped Windows Form (C#)

c#.netwinforms

提问by Matías

What is the easiest way to do this? Is it possible with managed code?

什么是最简单的方法来做到这一点?是否可以使用托管代码?

采纳答案by Geoff

this.BackgroundImage = //Image
this.FormBorderStyle = FormBorderStyle.None;
this.Width = this.BackgroundImage.Width;
this.Height = this.BackgroundImage.Height;
this.TransparencyKey = Color.FromArgb(0, 255, 0); //Contrast Color

This allows you to create a form based on an image, and use transparency index to make it seem as though the form is not rectangular.

这允许您基于图像创建表单,并使用透明度索引使其看起来好像表单不是矩形。

回答by Jobi Joy

@Geoff shows the right way in winforms.

@Geoff 在 winforms 中展示了正确的方式。

But If you are planning to use WPF instead of Winforms then WPF(.NET3.0+) gives very flexible ways to create anyshape custom windows. Check out this article also http://www.codeproject.com/KB/WPF/wpfpopup.aspx

但是,如果您打算使用 WPF 而不是 Winforms,那么 WPF(.NET3.0+) 提供了非常灵活的方法来创建 anyshape 自定义窗口。还可以查看这篇文章http://www.codeproject.com/KB/WPF/wpfpopup.aspx