Page 1 of 1

Drag and drop into Word

Posted: Fri Dec 12, 2008 6:55 am
by 10546313
Hi,
how can I drag and drop a chart into word ?
(Like copy and paste)

best regards
Werner

Posted: Fri Dec 12, 2008 12:00 pm
by narcis
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;