Solved

how to drag cursor in the manner of TListView

Posted on 2001-07-05
6
515 Views
Last Modified: 2011-09-20
in TListView dragging an item would yield a drag cursor in the form of the item caption (when listview is in vsReport viewstyle).

Is it possible to replicate this behaviour on a tlist or any other component ?
0
Comment
Question by:fadyg
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6254685
get the free drag&drop suite at
http://www.melander.dk/delphi/dragdrop/
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6254709
also look here for another components for drag and drop

http://www.torry.net/draganddrop.htm


0
 
LVL 8

Expert Comment

by:TOndrej
ID: 6254735
Yes, you can write a TDragObject descendant (overriding GetDragImages) and assign it to DragObject parameter in OnStartDrag event.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:fadyg
ID: 6255249
thanks all for the links

TOndrej, do you happen to have a small working example of your solution ?

FadyG
0
 
LVL 8

Accepted Solution

by:
TOndrej earned 300 total points
ID: 6255338
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
  TMyDragObject = class(TDragObject)
  private
    FDragImages: TDragImageList;
  protected
    function GetDragImages: TDragImageList; override;
  public
    constructor Create;
    destructor Destroy; override;
  end;

  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Label1StartDrag(Sender: TObject;
      var DragObject: TDragObject);
    procedure FormDragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure Label1EndDrag(Sender, Target: TObject; X, Y: Integer);
  private
    FDragObject: TMyDragObject;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TMyDragObject protected }

function TMyDragObject.GetDragImages: TDragImageList;
begin
  Result := FDragImages;
end;

{ TMyDragObject public }

constructor TMyDragObject.Create;
var
  B: TBitmap;
begin
  inherited Create;
  FDragImages := TDragImageList.CreateSize(32, 32);
  B := TBitmap.Create;
  B.Height := FDragImages.Height;
  B.Width := FDragImages.Width;
  try
    B.Canvas.Brush.Style := bsClear;
    B.Canvas.Ellipse(Rect(0, 0, 32, 32));
    B.Canvas.Font.Color := clRed;
    B.Canvas.TextOut(2, 4, 'Hello');
    FDragImages.AddMasked(B, clWhite);
  finally
    B.Free;
  end;
end;

destructor TMyDragObject.Destroy;
begin
  FDragImages.Free;
  inherited Destroy;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  { drag image is only displayed over controls which include csDisplayDragImage
    in their ControlStyle }
  ControlStyle := ControlStyle + [csDisplayDragImage];
end;

procedure TForm1.Label1StartDrag(Sender: TObject;
  var DragObject: TDragObject);
begin
  FDragObject := TMyDragObject.Create;
  DragObject := FDragObject;
end;

procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := True;
end;

procedure TForm1.Label1EndDrag(Sender, Target: TObject; X, Y: Integer);
begin
  FDragObject.Free;
end;

end.
0
 

Author Comment

by:fadyg
ID: 6255840
short and straight to the point
thanks !!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now