我按照你在这个帖子中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动画还能流畅的显示
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动画还能流畅的显示
this.pictureBox1.BackColor = Color.Transparent;//设置透明(其实就是和它所在容器的背景色相同而已)
this.pictureBox1.Image = Image.FromFile(@"C:\未命名.gif");//加载一个gif图片