博客
关于我
c#透明panel
阅读量:411 次
发布时间:2019-03-06

本文共 1711 字,大约阅读时间需要 5 分钟。

先看下效果

纯透明的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);            }        }    }
View Code

 

转载地址:http://tnvkz.baihongyu.com/

你可能感兴趣的文章
mysql中having的用法
查看>>
MySQL中interactive_timeout和wait_timeout的区别
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>
mysql中kill掉所有锁表的进程
查看>>
mysql中like % %模糊查询
查看>>
MySql中mvcc学习记录
查看>>
mysql中null和空字符串的区别与问题!
查看>>