«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» Help

How to create a TScrollBar with a background bitmap

   

The example listed below shows a scrollbar with a BackBitMap property. You can set any picture you like there and it will be painted as the background of the control.

{ ... }
  TMyPictureScrollBar = class(TScrollBar)
  protected
    FBackBitMap: TBitMap;
    procedure CNCtlColorScrollBar(var Msg: TMessage);
      message CN_CTLCOLORSCROLLBAR;
    procedure SetBackBitMap(AValue: TBitMap);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property BackBitMap: TBitMap read FBackBitMap write SetBackBitMap;
  end;

constructor TMyPictureScrollBar.Create(AOwner: TComponent);
begin
  FBackBitMap := TBitMap.Create;
  FBackBitMap.Canvas.Brush.Color := clYellow;
  inherited Create(AOwner);
end;

destructor TMyPictureScrollBar.Destroy;
begin
  FBackBitMap.Free;
  FBackBitMap := nil;
  inherited Destroy;
end;

procedure TMyPictureScrollBar.CNCtlColorScrollBar(var Msg: TMessage);
begin
  if not FBackBitMap.Empty then
    FBackBitMap.Canvas.Brush.Bitmap := FBackBitMap;
  Msg.Result := FBackBitMap.Canvas.Brush.Handle;
end;

procedure TMyPictureScrollBar.SetBackBitMap(AValue: TBitMap);
begin
  FBackBitMap.Assign(AValue);
  Invalidate;
end;
Original resource: The Delphi Pool
Author: Serge Gubenko
Added: 2009-10-28
Last updated: 2009-10-28

« Return to contents »