Link to home
Start Free TrialLog in
Avatar of joely
joely

asked on

Click, Drag, and Drop

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
ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Joely!

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

//Vik
Avatar of joely
joely

ASKER

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

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
Avatar of joely

ASKER

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
What edge are you talking about????

//Vik
Avatar of joely

ASKER

You try at design time.
You move a label to the other position.
You will look the edge only.

Joely
Avatar of joely

ASKER

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
Avatar of joely

ASKER

Hello Viktor

Do you have the solution ?

Joely
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
Avatar of joely

ASKER

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
I think you can change that if you create a descendant of TButton and set the cursor in OnDrag(Drop)(Over) to crYourCursor..

//Vik