透明的panel,可用用作遮罩层。
using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WinFormsApp1 { public class TransparentPanel : Panel { private const int WS_EX_TRANSPARENT = 0x20; public TransparentPanel() { SetStyle(ControlStyles.Opaque, true); } private int opacity = 1; [DefaultValue(1)] public int Opacity { get { return this.opacity; } set { if (value < 0 || value > 100) throw new ArgumentException("value must be between 0 and 100"); this.opacity = value; } } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT; return cp; } } protected override void OnPaint(PaintEventArgs e) { using (var brush = new SolidBrush(Color.FromArgb(this.opacity * 255 / 100, this.BackColor))) { e.Graphics.FillRectangle(brush, this.ClientRectangle); } base.OnPaint(e); } } }
欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步