一、使用AlphaBlend API 。这个可以看黎老师的文章。 见原文
下面转载一下:
.NET Framework的WinForm程序支持支持调节控件的透明度和GDI+,用它可以实现例如淡入淡出这种很酷的界面效果。而.NET Compact Framework的窗体和控件不支持透明和GDI+,因此常常利用图片来完成一些美观的程序界面效果,这样会使得程序包附带了很多用于交替的图片而体积变大。
今天看到了Windows Mobile 5.0/6上也有Alpha Blend API,可以用于实现一些透明的控件,如下图所示:
心动了吧?
上面的demo程序来自 AlphaMobileControls 的开源项目,AlphaMobileControls提供了一些可以实现透明效果的简单控件,如:AlphaLabel, AlphaPictureBox, AlphaImageButton 等,使用的时候必须将它们放到特殊的 AlphaPanel 或 AlphaForm 容器控件上。这套控件是通过封装了从Windows Mobile 5.0开始提供的 Imaging API 和 AlphaBlend() API 函数实现的,不能用在Windows Mobile 2003的程序上。另外,使用C/C++的朋友也可以参考相关的API,同样可以实现这种透明效果。
关于实现Windows Mobile Alpha Blend的细节,可以参考这篇文章:http://blogs.msdn.com/chrislorton/archive/2006/04/07/570649.aspx
另外,还有一种实现控件透明背景的方法,使用C/C++和API实现用画背景的Pattern Brush来画控件,产生效果如下:
这里不再多介绍,可以看原文:http://www.codeproject.com/KB/mobile/transparent_controls.aspx
二、SetColorKey实现透明效果
原文见MSDN How to: Draw Images with Transparency
实现方式:当渲染时将指定的颜色从位图中抽去,以达到透明效果:
第一步是建立在渲染时要被掩盖的color key(色度键)。我们需要指定一个精确的色度键值,而不是指定一个范围。

2

3

4

5

6

7

8

9
