窗口形式的C#透明背景

use*_*217 6 c# transparent winforms

我已经在winforms上看到了透明背景?

它不能解决我的问题.我使用相同的方法来尝试实现透明度

    public Form1()
    {
        this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        InitializeComponent();
        this.BackColor = Color.FromArgb(0, 0, 0, 0);
    }
Run Code Online (Sandbox Code Playgroud)

但这会产生灰色背景,而不是透明的.如何获得实际透明背景(注意,透明度键解决方案不提供透明背景,当我使用小于255的alpha通道绘制时,它与设置的表单背景颜色混合,而不是实际背景)?我想绘制到alpha <255的屏幕的某些区域并与背景(不是表单)混合.

Tom*_*zzo 18

我很久以前做的方法是为表单背景找到一个未使用的颜色,然后设置透明度键:

this.BackColor = Color.Magenta;
this.TransparencyKey = Color.Magenta;
Run Code Online (Sandbox Code Playgroud)

其他方式是:

  • 创建背景图像,使用特定颜色绘制透明区域并将其设置为BackgroundImage形式...然后将TransparencyKey设置为该颜色.
  • 使用空方法覆盖OnPaintBackground方法.

[编辑]正如马里奥所说,通常键的默认透明色是洋红色.

  • `Color.Magenta`通常被认为是默认的透明度键颜色.根据您正在处理的内容,这可能会使事情更容易重复使用.另外请记住,颜色键控仅支持1位alpha(即透明/不透明),但没有真正的8位alpha(或更多),这是OP正在寻找的. (3认同)