C#自定义控件背景色透明的方法
来源:互联网 发布:虎贲计算机二级软件 编辑:程序博客网 时间:2024/06/04 18:44
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); }}
阅读全文
0 0
- C#自定义控件背景色透明的方法
- c# lable控件背景色透明
- c#属性中get和set的作用 c#多窗口 lable控件背景色透明
- c#多窗口 lable控件背景色透明
- c#设置button、label等控件的背景色为透明
- 设置窗体上控件的背景色,设置控件背景色为透明
- 设控件背景色透明的程序效率问题
- CStatic控件的背景色设为透明?
- 怎样使控件的背景色为透明色?
- 设置listview等控件的透明背景色
- webkit 设置body背景色为透明的方法
- 使控件拥有透明背景色 [引用]
- 使控件拥有透明背景色
- winform 控件背景色设置成透明
- 在C#中使用透明背景色
- android设置背景色为透明,Button控件透明
- 改变控件的背景色
- 自定义UINavigationBar的背景色
- 会话控制系统session和Cookie
- 页面中验证码和文本框不对齐的情况
- 百度上传webuploader
- python3 如何转换html到pdf
- 中文分词组件
- C#自定义控件背景色透明的方法
- 视频监控中的多目标识别与跟踪技术
- Kafka,storm,Zookeeper,flume,Dubbo,Spark简介及应用
- C++ 简易string类实现(三)-抽离引用计数
- Call From SparkMaster/192.168.237.128 to 0.0.0.0:10020 failed on connection exception
- 格雷码Gray Code
- winform将图片嵌入到exe
- js 去掉字符串最后一个逗号
- [李景山php] 深入理解PHP内核[读书笔记]--第四章:函数的实现 --匿名函数及闭包