c#透明panel
2024-08-31 07:12:49
先看下效果
纯透明的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(, , width, height);
this.graphics.DrawImage(this.BackgroundImage, recModel);
}
else if (this.ForeColor != Color.Transparent)
{
this.graphics.Clear(this.ForeColor);
} } }
最新文章
- iOS-提高iOS开发效率的方法和工具
- 【ZJOI2013】k大数查询 BZOJ 3110
- 【GOF23设计模式】装饰模式
- haartraining生成.xml过程
- C++之路起航——标准模板库(list)
- POJ 1287 Networking (最小生成树)
- Object c中的alloc和init问题
- php中函数不确定参数个数时获取所有参数
- html加载与脚本运行中,由于html未完全加载而导致脚本找不到dom元素无法执行事件
- ZOJ 3483 简单if-else
- 中文里带半角空格导致的Text换行问题[Unity]
- 【一天一道LeetCode】#118. Pascal's Triangle
- mssql sqlserver updatetext关键字应用简介说明
- 【从零开始自制CPU之学习篇07】最简单的ALU—全加器
- python xpath学习
- F#周报2019年第10期
- map,set和weakmap,weakset
- Android源代码下载以及异常查找网站推荐
- MyEclipse Maven Tomcat
- Spring 一二事(6) - IOC MVC 简易搭建