Page 1 of 1

Problem with CopyToClipBoardMetafile with TRect

Posted: Tue May 11, 2010 8:12 am
by 10545837
Hi all,

Im using the Chart.CopyToClipBoardMetaFile(Enchanced:True;Rect:TRect), I just want to copy a square from the chart to display in PowerPoint. However no matter what left/Top coordinates i insert, the picture will always show with Left := 0 and Top :=0. The picture is correcly cut with the right/bottom properties but I cant change the left/top coordinates. Ofc i can manually crop the picture from left and top to the size I want but I just wanted to check with you guys if this procedure is working as intended. Any suggestions would be appreciated.

Best Regards,

Johan Ingemansson

Re: Problem with CopyToClipBoardMetafile with TRect

Posted: Wed May 12, 2010 8:59 am
by yeray
Hi Johan,

The rectangle given to CopyToClipBoardMetaFile function is the size you want the chart to be fitted, not the partial rectangle from the chart you want to obtain.
To take a part of the chart, you could manipulate a bitmap as follows:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var Bmp         : TBitmap;
    w, h        : Integer;
    DestRect    : TRect;
    SourceRect  : TRect;
begin
  Bmp:=TBitmap.Create;

  try
    w:=Chart1.ChartRect.Right-Chart1.ChartRect.Left;
    h:=Chart1.ChartRect.Bottom-Chart1.ChartRect.Top;

    DestRect:=Rect(0,0,w,h);
    SourceRect:=Chart1.ChartRect;

    Bmp:=Chart1.TeeCreateBitmap(clNone, Rect(0,0,Chart1.Width,Chart1.Height));
    Bmp.Canvas.CopyRect(DestRect,Bmp.Canvas,SourceRect);
    Bmp.Width:=w;
    Bmp.Height:=h;

    Clipboard.Assign(Bmp);
  finally
    Bmp.Free;
  end;
end;