type
TMyProgress =
class(TGraphicControl)
private
FBitmap: TBitmap;
FPosition: integer;
procedure SetPosition(
const Value: integer);
protected
procedure Paint;
override;
public
procedure SetBounds(ALeft, ATop, AWidth, AHeight: integer);
override;
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
property Position: integer
read FPosition
write SetPosition;
end;
...
//Code von delphi.about.com kopiert und leicht angepasst, ist ja nur ein Beispiel
procedure GradHorizontal(Canvas: TCanvas; Rect: TRect;
FromColor, ToColor: TColor);
var
X: integer;
dr, dg,
db: Extended;
C1, C2: TColor;
r1, r2, g1, g2, b1, b2: Byte;
R, G, B: Byte;
cnt: integer;
begin
C1 := FromColor;
r1 := GetRValue(C1);
g1 := GetGValue(C1);
b1 := GetBValue(C1);
C2 := ToColor;
r2 := GetRValue(C2);
g2 := GetGValue(C2);
b2 := GetBValue(C2);
dr := (r2 - r1) / Rect.Right - Rect.Left;
dg := (g2 - g1) / Rect.Right - Rect.Left;
db := (b2 - b1) / Rect.Right - Rect.Left;
cnt := 0;
for X := Rect.Left
to Rect.Right - 1
do
begin
R := r1 + round(dr * cnt);
G := g1 + round(dg * cnt);
B := b1 + round(
db * cnt);
Canvas.Pen.Color :=
RGB(R, G, B);
Canvas.MoveTo(X, Rect.Top);
Canvas.LineTo(X, Rect.Bottom);
inc(cnt);
end;
end;
constructor TMyProgress.Create(AOwner: TComponent);
begin
inherited;
FBitmap := TBitmap.Create;
Width := 200;
Height := 20;
end;
destructor TMyProgress.Destroy;
begin
FBitmap.Free;
inherited;
end;
procedure TMyProgress.Paint;
var
AWidth: integer;
begin
inherited;
AWidth := MulDiv(FPosition, Width, 100);
Canvas.CopyRect(Rect(0, 0, AWidth, Height), FBitmap.Canvas,
Rect(0, 0, AWidth, Height));
end;
procedure TMyProgress.SetBounds(ALeft, ATop, AWidth, AHeight: integer);
begin
inherited;
FBitmap.Width := AWidth;
FBitmap.Height := AHeight;
GradHorizontal(FBitmap.Canvas, Rect(0, 0, FBitmap.Width, FBitmap.Height),
RGB(255, 50, 50),
RGB(50, 255, 50));
Invalidate;
end;
procedure TMyProgress.SetPosition(
const Value: integer);
begin
FPosition := Value;
Invalidate;
end;