Solved

how to drag cursor in the manner of TListView

Posted on 2001-07-05
6
516 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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