惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
S
Secure Thoughts
月光博客
月光博客
美团技术团队
雷峰网
雷峰网
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
News and Events Feed by Topic
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Forbes - Security
Forbes - Security
W
WeLiveSecurity
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
爱范儿
爱范儿
G
GRAHAM CLULEY
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AI
AI
Last Week in AI
Last Week in AI
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
云风的 BLOG
云风的 BLOG
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Recent Announcements
Recent Announcements
Webroot Blog
Webroot Blog
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
罗磊的独立博客
The Register - Security
The Register - Security
Blog — PlanetScale
Blog — PlanetScale
T
Threat Research - Cisco Blogs
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
T
The Exploit Database - CXSecurity.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
B
Blog
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Engineering at Meta
Engineering at Meta
Latest news
Latest news
IT之家
IT之家
D
DataBreaches.Net
博客园 - 司徒正美
N
Netflix TechBlog - Medium
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - SuperCai

Leaf'n Joy 隐私政策 Leaf'n Joy (植物灯IOSAPP) WndProc(ref Message m) [转]DllImport属性详解 对C#插件接口应用的一些理解 日期时间格式化(到毫秒) [转]使用foreach 循环删除DataRow的时候的问题 UTC时间与WINDOWS时间互换 [转]C# Telnet [原]电子工程师工具箱 动态内存中加载DLL的问题 电缆电压降计算 红外对射探测器的安装方法 红外对射调试 终于想起了密码~~汗~~ 解决 Win2003 SP1 无法安装 - SuperCai .net创建windows Service步骤 用netsh自动切换IP
[转]C#自定义控件背景色透明的方法
SuperCai · 2012-10-25 · via 博客园 - SuperCai

在一项目要设置一自定义(画箭头)控件为透明色,以便控件叠加时可以完整显示线条,百度到以下文章,测试,效果达到要求.

转自:http://www.cnblogs.com/crid/archive/2009/05/24/1488495.html

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);
    }

}