天天看點

透明背景

繪制背景透明的圖檔,在有背景色的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);

}

     本文轉自xyz_lmn51CTO部落格,原文連結:http://blog.51cto.com/xyzlmn/819920,如需轉載請自行聯系原作者

繼續閱讀