【发布时间】:2011-07-09 05:58:34
【问题描述】:
如何在C# windows窗体应用中制作半透明窗体
我已经尝试了TransparentKey,它使其完全透明。并尝试了Opacity,但它会影响整个表单(带有控件)。
我只希望表单部分是半透明的,而不是控件。
【问题讨论】:
标签: c# winforms transparency
如何在C# windows窗体应用中制作半透明窗体
我已经尝试了TransparentKey,它使其完全透明。并尝试了Opacity,但它会影响整个表单(带有控件)。
我只希望表单部分是半透明的,而不是控件。
【问题讨论】:
标签: c# winforms transparency
我发现 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 服务器上执行:
【讨论】:
Control,但问题是关于Form...我会更新
你可以使用一个hatch brush 有一定的百分比,例如:
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);
}
【讨论】: