«« 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 use a TControlCanvas in a component

   
type
  TScrollingPaintBox = class(TScrollingWinControl)
  private
    FCanvas: TCanvas;
  public
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;
    property Canvas: TCanvas read FCanvas;
  end;

constructor TScrollingPaintBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FCanvas := TControlCanvas.Create;
  TControlCanvas(FCanvas).Control := Self;
end;

destructor TScrollingPaintBox.Destroy;
begin
  FCanvas.Free;
  inherited Destroy;
end;

A TControlCanvas is important because it creates a DC (device context) that belongs to the HWND of the control. Also, override is important on your constructor and destructor to ensure that they are actually called.

Original resource: The Delphi Pool
Author: Unknown
Added: 2009-08-12
Last updated: 2009-08-12

« Return to contents »