Solved

how to drag cursor in the manner of TListView

Posted on 2001-07-05
6
511 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:mnasman
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

18 Experts available now in Live!

Get 1:1 Help Now