绘制背景透明的图片,在有背景色的Form上显示透明图片,这是.NET CF本身提供的方法,关键是最后一个参数。

 

//在有背景色的Form上显示透明图片(事先准备背景透明的图片)
private void Form1_Paint(object sender, PaintEventArgs e)
{
Assembly asm = Assembly.GetExecutingAssembly();
Bitmap backgroundImage = new Bitmap(asm.GetManifestResourceStream("MyControl.TransparentImg.13.png"));

ImageAttributes attr = new ImageAttributes();
attr.SetColorKey(backgroundImage.GetPixel(0, 0), backgroundImage.GetPixel(0, 0));


e.Graphics.DrawImage(backgroundImage, new Rectangle(5, 5, 256, 256), 0, 0, 256, 256, GraphicsUnit.Pixel, attr);
}