E
emitsong
Unregistered / Unconfirmed
GUEST, unregistred user!
在Form中设置
TransparentColor:=true;
TransparentColorValue:=clnone;
color:=clnone;
结果发现了阴影变成了黑边,
如果将 form1.Brush.Style:=bsclear;上面的语句屏蔽,发现黑边没了,但窗口不透明了
看了TForm原码,发现用了下面代码
if not (csDesigning in ComponentState) and
(Assigned(SetLayeredWindowAttributes)) and HandleAllocated then
begin
AStyle := GetWindowLong(Handle, GWL_EXSTYLE);
if FAlphaBlend or FTransparentColor then
begin
if (AStyle and WS_EX_LAYERED) = 0 then
SetWindowLong(Handle, GWL_EXSTYLE, AStyle or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
end
else
begin
SetWindowLong(Handle, GWL_EXSTYLE, AStyle and not WS_EX_LAYERED);
RedrawWindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN);
end;
end;
/////////////////////////////////
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
关键这句里FTransparentColor如过为clnone,结果他当成黑的了,有没有空值表示方法,让他达到form1.Brush.Style:=bsclear;的效果,又有透明的功能,这样图片的阴影就完全显示出来了
注:我用了pngimage所以图片都为有阴影的透明图片
TransparentColor:=true;
TransparentColorValue:=clnone;
color:=clnone;
结果发现了阴影变成了黑边,
如果将 form1.Brush.Style:=bsclear;上面的语句屏蔽,发现黑边没了,但窗口不透明了
看了TForm原码,发现用了下面代码
if not (csDesigning in ComponentState) and
(Assigned(SetLayeredWindowAttributes)) and HandleAllocated then
begin
AStyle := GetWindowLong(Handle, GWL_EXSTYLE);
if FAlphaBlend or FTransparentColor then
begin
if (AStyle and WS_EX_LAYERED) = 0 then
SetWindowLong(Handle, GWL_EXSTYLE, AStyle or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
end
else
begin
SetWindowLong(Handle, GWL_EXSTYLE, AStyle and not WS_EX_LAYERED);
RedrawWindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN);
end;
end;
/////////////////////////////////
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
关键这句里FTransparentColor如过为clnone,结果他当成黑的了,有没有空值表示方法,让他达到form1.Brush.Style:=bsclear;的效果,又有透明的功能,这样图片的阴影就完全显示出来了
注:我用了pngimage所以图片都为有阴影的透明图片