在 c# 中将透明 Gif 图像添加到列表视图

本文关键字:添加 列表 视图 图像 Gif 透明 | 更新日期: 2023-09-27 18:30:46

我正在尝试将透明的 Gif 图像添加到列表视图中,我使用了以下代码片段以添加 GIF 图像。

// control as ListView 
void AddGiftoListView(Control parent)
{
    Bitmap img = (Bitmap)Properties.Resources.madLoader; // Transparent gif image
    Size sz = img.Size;
    PictureBox pbGif = new PictureBox();
    pbGif.Size = img.Size;
    pbGif.Image = img;
    parent.Controls.Add(pbGif);
    Point p = new Point(1, 1);
    pbGif.Location = p;
    pbGif.Show();
} 

但是 gif 不是透明的,当列表视图充满文本时,我们可以看到 gif 在上面有白色背景。 有什么办法解决这个问题吗?

谢谢世菊 P K

在 c# 中将透明 Gif 图像添加到列表视图

尝试将表单的透明度键设置为白色

this.TransparencyKey = Color.White;