Solved

Click, Drag, and Drop

Posted on 1998-09-26
12
469 Views
Last Modified: 2008-12-23
How to move caption on label to the other label using mouse while the program run.
The process looks the same if we copy file. Or looks like at the design time, when we move the label (drag a label to the other position) we can see the edge only.
If destination label already has a caption then the caption will be swap.

Joely
0
Comment
Question by:joely
  • 6
  • 6
12 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1340939
Lets say you have two labels on the form Label1 and Label2

//First set the property DragMode of Label1 to dmAutomatic

//Then enter the following code in the OnDragDrop() and OnDragOver() of Label2
procedure TForm1.Label2DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := Source is TLabel;
end;

procedure TForm1.Label2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  Label2.Caption := TLabel(Source).Caption;
end;

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340940
Hello Joely!

Does this help or you need some more help???

//Vik
0
 

Author Comment

by:joely
ID: 1340941
Hi... Viktor

How to make so the drag's process looks like at the design time, when we move the label (drag a label to the other position) we can see the edge only.

I add inside DragDrop's procedure, if destination label already has a caption then the caption will be swap and to check if source of label hasn't a caption is nothing.
Do you agree with me ?

procedure TForm1.Label2DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  s : string;

begin
  if TLabel(Source).Caption <> '' then
  begin
    s := (Sender as TLabel).Caption;
    (Sender as TLabel).Caption := TLabel(Source).Caption;
    TLabel(Source).Caption := s;
  end;
end;

Joely

0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 10

Expert Comment

by:viktornet
ID: 1340942
Yeah that's right. You swaped the values and exchanged the values of the captions with each other.... Anything else that you need, or maybe code/??

Regards,
Viktor ivanov
0
 

Author Comment

by:joely
ID: 1340943
Yes, I need code.

How to make so the drag's process looks like at the design time, when we move the label (drag a label to the other position) we can see the edge only.
Do you know what I mean ?
Is it possible to make it ?

Regards,
Joely
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340944
What edge are you talking about????

//Vik
0
 

Author Comment

by:joely
ID: 1340945
You try at design time.
You move a label to the other position.
You will look the edge only.

Joely
0
 

Author Comment

by:joely
ID: 1340946
Hi... Viktor

I want to explain, what is the edge ?
Have you tried ?
{This incident at design time}
If you click a label and you move (drag) a label to other position you can see as though a label brought. You just see rectangle (transparent) and default cursor (crArrow). And after you drop this label, a label has new position.
{This incident at runtime}
But in my case, I just want the drag's process like if we drag a label at design time. At runtime if we drag a label, the default cursor is crNoDrop.
And the position of label is same as before, not like at design time a label has a new position.
Just the drag's process.
I hope you understand.
Thanks.

Regards Joely
0
 

Author Comment

by:joely
ID: 1340947
Hello Viktor

Do you have the solution ?

Joely
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340948
Hello Joely. Sorry I didn't answer but I've been busy with my school work, and didn't have time to work with Delphi. It's true I've answered a few questions on E-E but it was easy and I'm sure your needs more work than the other questions... Ok, anyway, it's kinda late over here, but I'll start off with some info on your question...
-------------------
The first thing is that I know how to do that and here is the code for it....

if ssLeft in Shift then begin
  ReleaseCapture;
  TControl(Sender).Perform(WM_SYSCOMMAND, $F012, 0);
end;

This would move a component with a rectangle around it as you want, but there is a little trick there. It move controls, that have handles, and TLabel is a Graohical component that doesn't have a handle. This is the thing that keep us from being able to do that. If you can make a Label component that descends from a TControl or TWinControl then I think we'll be able to accomplish that. I'll experiment a little and will tell you how everything is going. Just want to tell you not to expect it to be fast. I got other things to do too. Maybe in a day or two I'll tell you where I'm up to...

btw- Please tell me what your e-mail address is so I can send you some code or some info on that if I find. Ok, talk to you later!

Regards,
Viktor Ivanov
0
 

Author Comment

by:joely
ID: 1340949
Hello Viktor

Previously I am sorry, I change the component.
I am using component descends from TWinControl, because if using TLabel to be found flicker (I am using TImage as a background).

// Comment for you
If using function that you given me, this component has a new position like at design time.
But I just want the drag's process like that and the position of this component is same as before (not to change).

// This is my idea
How if the process modify cursor's shape.
(Using Image Editor to make cursor shape !).
The process looks like this :

procedure ...StartDrag(...);
begin
  Cursor := crDragCursor;
end;

procedure ...DragOver(...);
begin
  ...
end;

procedure ...DragDrop(...);
begin
  ...
end;

procedure ...EndDrag(...);
begin
  Cursor := crDefault;
end;

But this way didn't work if mouse's cursor out of this component (the default is crNoDrop).


Joely
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340950
I think you can change that if you create a descendant of TButton and set the cursor in OnDrag(Drop)(Over) to crYourCursor..

//Vik
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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