[英]semi-transparent form but opaque Controls in C#
如何在 C# windows 窗体应用程序中制作半透明窗体
我已经尝试过使它完全透明的TransparentKey
。 并尝试了Opacity
,但它会影响整个表单(带有控件)。
我只希望表单部分是半透明的,而不是控件。
您可以使用具有一定百分比的阴影画笔,例如:
using System.Drawing.Drawing2D;
private void Form1_Paint(object sender, PaintEventArgs e)
{
var hb = new HatchBrush(HatchStyle.Percent50, this.TransparencyKey);
e.Graphics.FillRectangle(hb,this.DisplayRectangle);
}
我发现 Hatch Brush 很怪诞,
代替:
protected override void OnPaintBackground(PaintEventArgs e) { var hb = new HatchBrush(HatchStyle.Percent80, this.TransparencyKey); e.Graphics.FillRectangle(hb, this.DisplayRectangle); }
我用了:
protected override void OnPaintBackground(PaintEventArgs e) { var sb = new SolidBrush(Color.FromArgb(100, 100, 100, 100)); e.Graphics.FillRectangle(sb, this.DisplayRectangle); }
有一个解决方案可以为Control (不是Form )添加半透明度:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Apply opacity (0 to 255)
panel1.BackColor = Color.FromArgb(25, panel1.BackColor);
}
在 Visual Studio 中:(仅在执行期间激活 alpha)
在 Windows 7 上执行:
在旧的 WIndows 2003 Server 上执行:
来源: https ://stackoverflow.com/a/4464161/1529139
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.