Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Click, Drag, and Drop

Posted on 1998-09-26
12
Medium Priority
?
474 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
[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
  • 6
  • 6
12 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 400 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

704 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