title: Adding Canvas to TScrollBox
body: <p>I am trying to do simple thing: Add a Canvas property on the TScrollBox descendant. I have read <a href="https://stackoverflow.com/questions/9627831/how-to-make-a-tscrollbox-out-from-tcustomcontrol">this article</a></p>
  
  <p>but my ScrollBox descendant simply does not draw on the canvas. May anybody tell me, what is wrong?</p>
  
  <pre><code>  TfrmScrollContainer = class (TScrollBox)
    private
      FCanvas: TCanvas; 
      FControlState:TControlState;
      procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
    protected
      procedure Paint;
      procedure PaintWindow(DC: HDC); override;
      property Canvas: TCanvas read FCanvas;
    public
      constructor Create(AOwner: TComponent);  override;
      destructor Destroy; override;
    end;
  </code></pre>
  
  <p>...  this is exact copy, how TWincontrol turns to TCustomControl (but it fails somewhere)</p>
  
  <pre><code>constructor TfrmScrollContainer.Create(AOwner: TComponent);
  begin
    inherited Create(AOwner);
    FCanvas := TControlCanvas.Create;
    TControlCanvas(FCanvas).Control := Self;
  end;
  
  destructor TfrmScrollContainer.Destroy;
  begin
    FCanvas.Free;
    inherited Destroy;
  end;
  
  procedure TfrmScrollContainer.WMPaint(var Message: TWMPaint);
  begin
    Include(FControlState, csCustomPaint);
    inherited;
    Exclude(FControlState, csCustomPaint);
  end;
  
  procedure TfrmScrollContainer.PaintWindow(DC: HDC);
  begin
    FCanvas.Lock;
    try
      FCanvas.Handle := DC;
      try
        TControlCanvas(FCanvas).UpdateTextFlags;
        Paint;
      finally
        FCanvas.Handle := 0;
      end;
    finally
      FCanvas.Unlock;
    end;
  end;
  
  procedure TfrmScrollContainer.Paint;    // this is not executed (I do not see any ellipse)
  begin
    Canvas.Brush.Color:=clRed;
    Canvas.Ellipse(ClientRect);
  end;
  </code></pre>
  
  <p>Thanx</p>