procedure DrawAnyShapeControl(ControlHandle:THandle;Canvas:TCanvas;MaskColor:TColor);
var
dc:hdc;
rgn:hrgn;
x,y,w,h:integer;
coord:tpoint;
line:boolean;
color:tcolor;
begin
dc:=getwindowdc(controlhandle);
beginpath(dc);
w:=canvas.cliprect.Right;
h:=canvas.ClipRect.Bottom;
for x:=0 to w-1 do
begin
line:=false;
for y:=0 to h-1 do
begin
color:=canvas.Pixels[x,y];
if color<>maskcolor then
begin
if not line then
begin
line:=true;
coord.X:=x;
coord.Y:=y;
end;
end;
if (color=maskcolor) or (y=h -1) then
begin
if line then
begin
line:=false;
movetoex(dc,coord.X,coord.Y,nil);
lineto(dc,coord.x,y);
lineto(dc,coord.x+1,y);
lineto(dc,coord.X+1,coord.Y);
closefigure(dc);
end;
end;
end;
end;
endpath(dc);
rgn:=pathtoregion(dc);
releasedc(controlhandle,dc);
//////////////////////
if rgn<>0 then
begin
setwindowrgn(controlhandle,rgn,true) ;
end;