Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8934367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:46:06+00:00 2026-06-15T09:46:06+00:00

I have an TImage on a TPanel, and an other (empty) TPanels. I want

  • 0

I have an TImage on a TPanel, and an other (empty) TPanels. I want to drag
the image from the first to the second panel using the drag and drop.

I actually want to see the image while it’s moving from one panel to the
other (semi-transparent).

I think I should use TDragObject.GetDragImages but I can’t figure out how to construct the whole magic.

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Image1.ControlStyle := Image1.ControlStyle + [csDisplayDragImage]; // ???
  TImage(Sender).BeginDrag(False);
end;

procedure TForm1.Image1StartDrag(Sender: TObject; var DragObject: TDragObject);
begin
  // ???
end;

procedure TForm1.Panel1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  if (Source is TImage) then
    Accept := TImage(Source).Parent <> Sender;
end;

procedure TForm1.Panel1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  if (Source is TImage) then
  begin
    TImage(Source).Parent := TPanel(Sender);
    TImage(Source).Align := alClient;
  end;
end;

Update – I found a useful article: Implementing Professional Drag & Drop In VCL/CLX Applications

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:46:07+00:00Added an answer on June 15, 2026 at 9:46 am
    unit Unit3;
    
    interface
    // 2012 Thomas Wassermann - demo
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,  ExtCtrls;
    
    type
    
    
      TMyDragObject = class(TDragControlObject)
      private
        FImageList:TImageList;
        FDragSource:TControl;
      protected
        function GetDragImages: TDragImageList; override;
      public
        Procedure StartDrag(G:TGraphic;p:TPoint;DragSource:TControl);
        Constructor Create(AControl: TControl); override;
        Destructor Destroy;override;
        Property DragSource:TControl read FDragSource;
      end;
    
    
    
      TForm3 = class(TForm)
        Panel1: TPanel;
        Panel2: TPanel;
        Image1: TImage;
        procedure Image1StartDrag(Sender: TObject; var DragObject: TDragObject);
        procedure FormCreate(Sender: TObject);
        procedure Panel1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
        procedure FormDestroy(Sender: TObject);
        procedure Panel1DragDrop(Sender, Source: TObject; X, Y: Integer);
      private
        { Private-Deklarationen }
        FDragObject:TMyDragObject;
      public
        { Public-Deklarationen }
      end;
    
    var
      Form3: TForm3;
    
    implementation
    
    constructor TMyDragObject.Create(AControl: TControl);
    begin
      inherited;
      FImageList:=TImageList.Create(nil);
    end;
    
    destructor TMyDragObject.Destroy;
    begin
      FImageList.Free;
      inherited;
    end;
    
    function TMyDragObject.GetDragImages: TDragImageList;
    begin
       Result := FImageList;
    end;
    
    {$R *.dfm}
    
    procedure TMyDragObject.StartDrag(G: TGraphic;p:TPoint;DragSource:TControl);
    var
     bmp:TBitMap;
    begin
       FDragSource := DragSource;
       bmp:=TBitMap.Create;
       try
       FImageList.Width := g.Width;
       FImageList.Height := g.Height;
       bmp.Width := g.Width;
       bmp.Height := g.Height;
       bmp.Canvas.Draw(0,0,g);
       FImageList.Add(bmp,nil);
       finally
         bmp.Free;
       end;
        FImageList.SetDragImage(0,p.x,p.y)
    end;
    
    procedure TForm3.FormCreate(Sender: TObject);
    var
     i:Integer;
    begin
      ControlStyle := ControlStyle + [csDisplayDragImage];
      for I := 0 to ControlCount -1  do
          if Controls[i] is TPanel then
             TPanel(Controls[i]).ControlStyle := TPanel(Controls[i]).ControlStyle + [csDisplayDragImage];
      ReportMemoryLeaksOnShutDown := True;
    end;
    
    procedure TForm3.FormDestroy(Sender: TObject);
    begin
      if Assigned(FDragObject) then FDragObject.Free;
    end;
    
    procedure TForm3.Image1StartDrag(Sender: TObject; var DragObject: TDragObject);
    var
     p:TPoint;
    
    begin
        p:=TImage(Sender).ScreenToClient(mouse.cursorpos);
        if Assigned(FDragObject) then FDragObject.Free;
        FDragObject := TMyDragObject.Create(TImage(Sender));
        FDragObject.StartDrag(TImage(Sender).Picture.Graphic,p,TImage(Sender));
        DragObject := FDragObject;
    end;
    
    procedure TForm3.Panel1DragDrop(Sender, Source: TObject; X, Y: Integer);
    begin
      if FDragObject.DragSource is TImage then
        TImage(FDragObject.DragSource).Parent := TPanel(Sender);
    end;
    
    procedure TForm3.Panel1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
    begin
        Accept := Source is TMyDragObject;
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have TPanel. On this Panel there is an TImage descendant , few other
I have a Delphi application which displays an image using a TImage. The location
I want to create a custom control derived from TPanel that contains an image
I have problem to display my Picture in TImage from my MySql database using
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have a Delphi 6 application that receives and processes an image stream from
I have a PNG (32-bit) image in a TImage. A form has a Glass
I have a TImage component that I print a Text string to using TCanvas.TextOut().
I am working with delphi. I have TImage, to which I assign a bitmap.
I am developing a Delphi application. On TImage.MouseDown event I want to do X

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.