C#自定义控件背景色透明的方法
I struggled for ages with the problem of having controls show through a control that was painted on top of them. It seems that ControlStyles.SupportsTransparentBackColor just allowed the control to pick up the container's background colour/image and wouldn't prevent the control from hiding any controls that were underneath it. I eventually found an answer so I thought I would post it here. This code example of a Pointer class, will take an alpha-blended png in the constructor and allow all the controls behind it to show through the transparent or semi-transparent pixels in the png, even when the pointer's location is changed ...
public class Pointer : Control
{
public Pointer(Image image)
: base()
{
Image = image;
SetStyle(ControlStyles.SupportsTransparentBackColor
| ControlStyles.UserPaint
| ControlStyles.AllPaintingInWmPaint
| ControlStyles.Opaque, true);
BackColor = Color.Transparent;
} protected override void OnLocationChanged(EventArgs e)
{
// pick up the container's surface again.
Visible = false;
Visible = true;
} protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
} private Image image;
public Image Image
{
get
{
return image;
}
set
{
image = value;
Size = image.Size;
}
} protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
pe.Graphics.DrawImage(image, 0, 0);
} }
C#自定义控件背景色透明的方法的更多相关文章
- Css:背景色透明,内容不透明之终极方法!兼容所有浏览器
转载 http://www.cnblogs.com/jikey/archive/2012/08/31/2665880.html <!DOCTYPE html PUBLIC "-//W3 ...
- Qt修改图片的背景色及设置背景色为透明的方法
先上干货. Qt下修改图片背景色的方法: 方法一: QPixmap CKnitWidget::ChangeImageColor(QPixmap sourcePixmap, QColor origCol ...
- 使用IE滤镜实现css3中rgba让背景色透明的效果
让背景透明,听上去不是挺容易的么? 让背景色透明,很容易想到opacity,要兼容IE的话只要加上filter:alpha(opacity=?)就行了,OK,看看这个例子. html: <div ...
- php imagemagick 处理 图片剪切、压缩、合并、插入文本、背景色透明
php有一款插件叫做imagemagick,功能很强大,提供了图片的很多操作,图片剪切.压缩.合并.插入文本.背景色透明等.并且有api方法调用和命令行操作两种方式,如果只是简单处理的话建议api方法 ...
- 如何让iframe背景色透明框架页文件设置
如何让iframe背景色透明框架页文件设置:<body style="background-color:transparent" > 或 <body bgColo ...
- css 背景色渐变---和背景色透明
1 背景色渐变 background:#fb0000; background: -webkit-gradient(linear, left top, left bottom, color-stop(0 ...
- opacity的背景透明&background中rgba的背景色透明
近期使用css实现了一个loading旋转加载的图片效果,类似gif动画 过程中,需要透明背景,但是图片不要透明 只要背景透明!只要背景透明!只要背景透明! 这里对透明模糊了,两种写法,模糊了 A: ...
- winform中按钮透明的方法
把Button设为透明的方法:1.修改 FlatAppearance属性下的BorderSize 为0 修改 FlatStyle 的属性为 Flat 2. /// <summary>// ...
- CSS3背景色透明(兼容IE8)
标准浏览器通过rgba()实现背景色透明;IE8以下浏览器通过特有滤镜实现背景色透明. 代码如下: 1 /* IE8 */ 2 filter:progid:DXImageTransform.Micro ...
随机推荐
- csu 1326 The contest
裸的 并查集 + 分组背包: #include<iostream> #include<cstring> #include<algorithm> #inclu ...
- Java中sychronized方法与sychronized块区别
一.举几个栗子
- 【转】使用Xcode和Instruments调试解决iOS内存泄露
原文网址:http://blog.csdn.net/totogo2010/article/details/8233565 虽然iOS 5.0版本之后加入了ARC机制,由于相互引用关系比较复杂时,内存泄 ...
- dubbo-admin在jdk 1.8上部署出错问题
今天在linux上部署dubbo-admin-2.5.4,一直报错: ERROR context.ContextLoader - Context initialization failedorg.sp ...
- cocos2dx lua中继承与覆盖C++方法
cocos2dx的extern.lua中的class方法为lua扩展了面向对象的功能,这使我们在开发中可以方便的继承原生类 但是用function返回对象的方法来继承C++类是没有super字段的,这 ...
- SQL语句构建器类
问题 Java程序员面对的最痛苦的事情之一就是在Java代码中嵌入SQL语句.这么来做通常是由于SQL语句需要动态来生成-否则可以将它们放到外部文件或者存储过程中.正如你已经看到的那样,MyBatis ...
- VB6.0编程笔记——(1)篇外篇&目录
从计算机专业毕业到进入IT行业,说来也有些年头了.相比较而言算是幸运,也有很多的同学进入了其他行业,也有一些朋友又想进入这个行业.现在回想自己的一路历程,总结一下,也是一份记忆. 基于以上的原因,希望 ...
- Nginx中的upstream轮询机制介绍
Nginx中upstream有以下几种方式: 1.轮询(weight=1) 默认选项,当weight不指定时,各服务器weight相同, 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器d ...
- LoadRunner中常见参数和变量
1.参数和字符串变量的交换 ①lr_save_string(“hello world”,“param”) 将hello world 保存在参数 param中 ②lr_eval_stri ...
- 【转】linux打包压缩命令
转自:http://www.cnblogs.com/end/archive/2011/04/20/2022614.html tar命令 [root@linux ~]# tar [-cxtzjvfpPN ...