Solved

Click, Drag, and Drop

Posted on 1998-09-26
12
470 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
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.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tidtcpserver connection lost handle 2 102
how to change, disabled button color FMX ? 1 40
MS Access from Delphi 31 60
firemonkey Android Listview Sort items 7 50
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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