procedure fillGradientRect(canvas: tcanvas; Recty: trect; fbcolor, fecolor: tcolor; fcolors: integer);
var
i, j, h, w, fcolor: Integer;
R, G, B: Longword;
beginRGBvalue, RGBdifference: array[0..2] of Longword;
begin
beginRGBvalue[0] := GetRvalue(colortoRGB(FBcolor));
beginRGBvalue[1] := GetGvalue(colortoRGB(FBcolor));
beginRGBvalue[2] := GetBvalue(colortoRGB(FBcolor));
RGBdifference[0] := GetRvalue(colortoRGB(FEcolor)) - beginRGBvalue[0];
RGBdifference[1] := GetGvalue(colortoRGB(FEcolor)) - beginRGBvalue[1];
RGBdifference[2] := GetBvalue(colortoRGB(FEcolor)) - beginRGBvalue[2];
canvas.pen.style := pssolid;
canvas.pen.mode := pmcopy;
j := 0;
h := recty.bottom - recty.top;
w := recty.right - recty.left;
for i := fcolors downto 0 do
begin
recty.left := muldiv(i - 1, w, fcolors);
recty.right := muldiv(i, w, fcolors);
if fcolors>1 then
begin
R := beginRGBvalue[0] + muldiv(j, RGBDifference[0], fcolors);
G := beginRGBvalue[1] + muldiv(j, RGBDifference[1], fcolors);
B := beginRGBvalue[2] + muldiv(j, RGBDifference[2], fcolors);
end;
canvas.brush.color := RGB(R, G, B);
patBlt(canvas.handle, recty.left, recty.top, Recty.right - recty.left, h, patcopy);
inc(j);
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
Row, Ht: Word;
IX: Integer;
begin
fillGradientRect(form1.canvas, rect(0, 0, Width, Height), $FF0000, $00000, $00FF);
iX :=200 ;
Ht:=(ClientHeight + 512) div 256;
for Row := 0 to 512 do
begin
with Canvas do begin
Brush.Color := RGB(Ix,0,row);
FillRect(Rect(0, Row * Ht, ClientWidth, (Row + 1) * Ht));
IX :=(IX-1);
end;
end;
{Note, that the OnResize event should also call the FormPaint
method if this form is allowed to be resizable.
This is because if it is not called then when the
window is resized the gradient will not match the rest of the form. }
موضوع :

