c#透明panel
先看下效果
纯透明的pane,然后设置一个半透明的图片,可以看出来显示了父控件的button
看代码
public partial class PanelEx : Panel { protected Graphics graphics; protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; // 实现透明样式 return cp; } } public PanelEx() { InitializeComponent(); this.BackColor = Color.Transparent; this.ForeColor = Color.Transparent; } protected override void OnPaintBackground(PaintEventArgs pevent) { } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); this.graphics = e.Graphics; this.graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; this.graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; this.graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; this.graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; this.graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; if (this.BackgroundImage != null) { int width = this.Width; int height = this.Height; Rectangle recModel = new Rectangle(0, 0, width, height); this.graphics.DrawImage(this.BackgroundImage, recModel); } else if (this.ForeColor != Color.Transparent) { this.graphics.Clear(this.ForeColor); } } }
作者:冰封一夏
出处:http://www.cnblogs.com/bfyx/
HZHControls官网:http://www.hzhcontrols.cn
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git