Drag and drop into Word

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Werner
Newbie
Newbie
Posts: 46
Joined: Mon Aug 06, 2007 12:00 am

Drag and drop into Word

Post by Werner » Fri Dec 12, 2008 6:55 am

Hi,
how can I drag and drop a chart into word ?
(Like copy and paste)

best regards
Werner

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Dec 12, 2008 12:00 pm

Hi Werner,

With TeeChart you can copy a chart image to the clipboard and then paste it at the application you wish. However TeeChart doesn't support drag and drop. For that you could export TeeChart to an image and use Raize's DropMaster for dragging it into Word. We use this component for internal software and it includes an example on how to drag an image from a Delphi application. I have tried it and could drop the image successfully into word.

Applying such example with TeeChart could be something like this:

Code: Select all

uses
  DMUtil;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues();
  Image1.Picture.Bitmap:=Chart1.TeeCreateBitmap;
  Chart1.Visible:=false;
  Panel1.Left:=Chart1.Left;
  Panel1.Top:=Chart1.Top;
  Panel1.Width:=Chart1.Width;
  Panel1.Height:=Chart1.Height;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  aBmp: TBitmap;
begin
  // Detect a drag with any button
  if DragDetectEx(Panel1.Handle, POINT(X,Y), Button) then
  begin
    // Tell the graphic source which button we got.
    DMGraphicSource1.MouseButton := Button;

    // Make a temporary bitmap
    aBMP := TBitmap.create;
    try
      // Assign the (JPEG) graphic to the bitmap, which converts the
      // JPEG to a bitmap.
      aBmp.Assign(Image1.Picture.Graphic);

      // Now, we have a bitmap, so assign it to the graphic source's picture
      DMGraphicSource1.Picture.Graphic := aBmp;

      // Now do the drag!
      DMGraphicSource1.Execute;

      // In case we made a big bitmap, let it go.  Otherwise, it will live
      // on unnecessarily in the Picture property of the TDMGraphicSource.
      DMGraphicSource1.Picture := nil;
    finally
      // Clean up.
      aBmp.Free;
    end;
  end;
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply