Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Show TLabel's content while dragging to TMemo and vice versa

Posted on 2004-10-27
19
Medium Priority
?
655 Views
Last Modified: 2010-04-05
Anybody here knows how to show the content of TLabel while dragging to TMemo and vice versa? I'm having a hard time finding a reference about it. Thanks in advance.

edwin
0
Comment
Question by:edeaux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
  • 2
19 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12430568
you have to add OLE Drag&Drop support to your app
one example is : http://delphi.icm.edu.pl/ftp/d30free/gwdrgdrp.zip
and the other easier way is to use Drag&Drop Suite
http://www.users.on.net/johnson/delphi/dragdrop0400.exe
or check how it's done in VirtualTreeView: http://www.soft-gems.net/VirtualTreeview/VT.php
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 80 total points
ID: 12431045
0
 

Author Comment

by:edeaux
ID: 12431154
thanks for the post Kretz :) I have one thing to ask. How to create a bitmap of the Label? I need to show the label itself while dragging and also hide the drag cursor so only the label will be shown.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12431306
:)

just copy the canvas'

a small mod and it will do:

  TMyDragObject = class(TDragObject)
  private
    FDragImages: TDragImageList;
  protected
    function GetDragImages: TDragImageList; override;
    function GetDragCursor(Accepted: Boolean; X: Integer;
      Y: Integer): TCursor; override;
  public
    constructor Create(ALabel: TLabel);
    destructor Destroy; override;
  end;

constructor TMyDragObject.Create(ALabel: TLabel);
var
  B: TBitmap;
begin
  inherited Create;
  FDragImages := TDragImageList.CreateSize(ALabel.Width, ALabel.Height);
  B := TBitmap.Create;
  B.Height := FDragImages.Height;
  B.Width := FDragImages.Width;
  try
    B.Canvas.CopyRect(Rect(0, 0, B.Width, B.Height), ALabel.Canvas, Rect(0, 0, B.Width, B.Height));
    FDragImages.AddMasked(B, ALabel.Color);
  finally
    B.Free;
  end;
end;

function TMyDragObject.GetDragCursor(Accepted: Boolean; X,
  Y: Integer): TCursor;
begin
  Result:=crNone;
end;
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12431319
oh .. and in LabelStartDrag change:
FDragObject := TMyDragObject.Create(Label1);
0
 

Author Comment

by:edeaux
ID: 12431529
thanks Lee :) I want to hide the label when it is dropped to a control like memo or anything that could accept a text from the caption of the label. I tried assigning the visible value of label to false but there was a portion of label visible. I put the assignment inn LabelStartDrag event.
0
 

Author Comment

by:edeaux
ID: 12431551
Anyway I wanted to mimic a drag and move. In that way i can move back the caption of the label to its original caption.
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 560 total points
ID: 12431670
something like this then:

(descend from TDragObjectEx so it's automatically free'd)

unit Unit1;

interface

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

type
  TMyDragObject = class(TDragObjectEx)
  private
    FDragImages: TDragImageList;
    FLabel: TLabel;
  protected
    function GetDragImages: TDragImageList; override;
    function GetDragCursor(Accepted: Boolean; X: Integer;
      Y: Integer): TCursor; override;
  public
    constructor Create(ALabel: TLabel);
    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);
  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(ALabel: TLabel);
var
  B: TBitmap;
begin
  inherited Create;
  FLabel:=ALabel;
  FDragImages := TDragImageList.CreateSize(ALabel.Width, ALabel.Height);
  B := TBitmap.Create;
  B.Height := FDragImages.Height;
  B.Width := FDragImages.Width;
  try
    B.Canvas.CopyRect(Rect(0, 0, B.Width, B.Height), ALabel.Canvas, Rect(0, 0, B.Width, B.Height));
    FDragImages.AddMasked(B, ALabel.Color);
  finally
    B.Free;
  end;
  ALabel.Visible:=false;
  ALabel.Update;
end;

destructor TMyDragObject.Destroy;
begin
  if not Dropped then
    FLabel.Visible:=true;
  FDragImages.Free;
  inherited Destroy;
end;


function TMyDragObject.GetDragCursor(Accepted: Boolean; X,
  Y: Integer): TCursor;
begin
  Result:=crNone;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ControlStyle := ControlStyle + [csDisplayDragImage];
end;

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

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

end.
0
 

Author Comment

by:edeaux
ID: 12431900
why is it the dropped property of TMyDragObject becomes True even drop to itself? That makes the label invisible even isn't drop to other control.
0
 

Author Comment

by:edeaux
ID: 12431912
How to check if the dropping is successful to the target control? I'm asking Lee.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12432317
TDragObject has a property Dropped
that's what I checked in the example and set the labels visible to true/false
0
 

Author Comment

by:edeaux
ID: 12432434
anybody here knows how to check if the dropping to other control is successful or not?
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12432718
? use the 'other control's' OnDragDrop event
0
 

Author Comment

by:edeaux
ID: 12432743
I found out that when the DragObject in Label's StartDrag is assigned a Class derived from TDragObject the EndDrag won't trigger. If the said event triggered i could set visible into true if the target is nil. Any idea how to trigger the event? I increased the points to 160.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12432859
why don't you check that in your TDragObject descendant ?

destructor TMyDragObject.Destroy;
begin
  if (not Dropped) or (DragTarget = nil) then
    FLabel.Visible:=true;
  FDragImages.Free;
  inherited Destroy;
end;
0
 

Author Comment

by:edeaux
ID: 12433064
i got it :) I created a field class name FSuccessfulDropped in the TMyDragObject that could be used to check if the dropped to other control is successful or not and used it on Lee_Nover recent post (changed DragTarget to FSuccessfulDropped).
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12433269
thanks for the points, edeaux, i did not exepected it ;-)

lee did a great job, well done

meikl ;-)
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12433458
tnx :)

just yesterday I implemented OLE d&d for VTV .. so I was warmed up :)
0
 

Author Comment

by:edeaux
ID: 12441820
you're welcome kretz :) yeah you're right he's the guy :)
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

610 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