Problem with CopyToClipBoardMetafile with TRect

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
JohanI
Newbie
Newbie
Posts: 5
Joined: Fri Jun 29, 2007 12:00 am

Problem with CopyToClipBoardMetafile with TRect

Post by JohanI » Tue May 11, 2010 8:12 am

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

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problem with CopyToClipBoardMetafile with TRect

Post by Yeray » Wed May 12, 2010 8:59 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply