我按照你在这个帖子中http://topic.csdn.net/u/20081130/01/befbf04d-5274-47c3-a405-d258f7e78195.html说的方法重写了picturebox控件using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;namespace TestPrj
{
    public partial class TransparentPictureBox : PictureBox
    {
        public TransparentPictureBox()
        {
            InitializeComponent();
        }        protected override CreateParams CreateParams
        {
            get
            {
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
                
                const int WS_EX_TRANSPARENT = 0x20;
                CreateParams result = base.CreateParams;
                result.ExStyle = result.ExStyle | WS_EX_TRANSPARENT;
                return result;
            }
        }
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            //base.OnPaintBackground(pevent);
        }
    }
}
确实实现了背景透明 ,但是gif图片的幻影十分严重,如果我把this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);改为this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
背景就不透明了,成了黑色
怎样让picturebox的背景真正的透明,并且gif动画还能流畅的显示

解决方案 »

  1.   

    不需要这么麻烦吧。
    this.pictureBox1.BackColor = Color.Transparent;//设置透明(其实就是和它所在容器的背景色相同而已)
    this.pictureBox1.Image = Image.FromFile(@"C:\未命名.gif");//加载一个gif图片
      

  2.   

    我需要两个pictureBox叠加在一起,pictureBox.BackColor = Color.Transparent;是不行的
      

  3.   

    我的回帖(c#中的Label控件就是不能实现真正的背景透明吗? )并没有针对gif动画测试过,对你的问题我也没有好的方案。建议向其他朋友提问,或换另外的方案。