To haoslm:
不好意思,才看到,你不就是想加点渐变色,直说不就得了,拐弯抹角干吗啊。
需要用到 GDIPlus 系列单元,网上有的是。
uses GDIPAPI, GDIPOBJ;
function MakeColor(Color: TColor; Alpha: Byte): TGPColor;
var
rgb: COLORREF;
begin
rgb := ColorToRGB(Color);
Result := (GetBValue(rgb) shl BlueShift) or (GetGValue(rgb) shl GreenShift) or
(GetRValue(rgb) shl RedShift) or (DWORD(Alpha) shl AlphaShift);
end;
procedure SetRoundRectShadow(Canvas: TCanvas; x1, y1, x2, y2, WidthEllipse, HeightEllipse, Shadow: Integer;
Color1, Color2: TColor; Alpha: Byte);
var
g: TGPGraphics;
b: TGPLinearGradientBrush;
hrgnBk, hrgnFr: HRGN;
r: TGPRegion;
begin
g := TGPGraphics.Create(Canvas.Handle);
b := TGPLinearGradientBrush.Create(MakePoint(x1, y1), MakePoint(x2 + Shadow, y2 + Shadow),
MakeColor(Color1, Alpha), MakeColor(Color2, Alpha));
hrgnFr := CreateRoundRectRgn(x1, y1, x2, y2, WidthEllipse, HeightEllipse);
hrgnBk := CreateRoundRectRgn(x1 + Shadow, y1 + Shadow, x2 + Shadow, y2 + Shadow,
WidthEllipse, HeightEllipse);
CombineRgn(hrgnBk, hrgnBk, hrgnFr, RGN_DIFF);
r := TGPRegion.Create(hrgnBk);
g.FillRegion(b, r);
r.Free;
DeleteObject(hrgnFr);
DeleteObject(hrgnBk);
b.Free;
g.Free;
end;
//用的时候这样用
procedure TForm1.Button1Click(Sender: TObject);
begin
SetRoundRectShadow(Canvas, 100, 100, 300, 300, 60, 60, 8, clBlack, clBtnFace, 255);
end;