Solved

how to drag cursor in the manner of TListView

Posted on 2001-07-05
6
522 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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