Solved

Click, Drag, and Drop

Posted on 1998-09-26
12
466 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
Comment Utility
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
Comment Utility
Hello Joely!

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

//Vik
0
 

Author Comment

by:joely
Comment Utility
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
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
What edge are you talking about????

//Vik
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:joely
Comment Utility
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
Comment Utility
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
Comment Utility
Hello Viktor

Do you have the solution ?

Joely
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now