请教一下, 怎样让用户自定义控件实现背景透明.特别是当多个控件重叠时.
现在运行时的效果下如图:
请问, 怎样让控件白色的部份变为透明呢?
#region 透明
public bool drag = false;
public bool enab = false;
private Color fillColor = Color.White;
private int opacity = 100;
public Color FillColor
{
get
{
return this.fillColor;
}
set
{
this.fillColor = value;
if (this.Parent != null) Parent.Invalidate(this.Bounds, true);
}
}
public int Opacity
{
get
{
if (opacity > 100) { opacity = 100; }
else if (opacity < 1) { opacity = 1; }
return this.opacity;
}
set
{
this.opacity = value;
if (this.Parent != null) Parent.Invalidate(this.Bounds, true);
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
#endregion
/// <summary>
/// 用指定的屏蔽颜色返回指定位图的GraphicsPath对象,该方法不能返回JPG图象的区域!
/// </summary>
/// <param name="Bmp">指定的位图</param>
/// <param name="TransparentColor">图象中要屏蔽的颜色</param>
/// <returns>Returns GraphicsPath</returns>
//如果要取得Region对象: Region region = new Region(GetBitmapRegion(...)返回值)
//this.Region = region 即可将窗口区域转换该图形样式(在Form_Load(...)中)
public static GraphicsPath GetBitmapPath(Bitmap Bmp)
{
if (Bmp == null) return null;
GraphicsPath Path = new GraphicsPath();//创建图形路径
int x = 0, y = 0;
Rectangle Rect;
for (x = 0; x <= Bmp.Width - 1; x++) //x方向
{
for (y = 0; y <= Bmp.Height - 1; y++) //y方向
{
Rect = new Rectangle(x, y, 1, 1);//创建一个单像素矩型区域,非屏蔽色点的坐标
Path.AddRectangle(Rect);
}
}
return Path;
}