[英]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.