Autor Beitrag
Hoda
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Mi 09.10.02 17:18 
Hallo,
da bin ich wieder. :wink:

Erzeugen und ansprechen der Dynamisch erzeugten Labels funktioniert. :D

Leider kann ich nicht die Dynamisch erzeugten Labels per ONMouseMove von A nach B verschieben.
Nur wenn ich nicht auf die Labels direkt klicke, funktioniert die Verschiebung. :shock:

Natürlich ist dies nicht elegant, wenn man überlegt, dass man erst neben dem Objekt klicken muss den man verschieben will!

Mein Frage ist: Wie kann ich die Dynamisch erzeugten Labels, mit klick auf die selbst, von A nach B verschieben?

Hier der Code:
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
var OBName :String;

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
for i := 1 to 5 do begin
  MyLabel := TLabel.Create(self);
  MYlabel.Parent := self;
  Mylabel.Name := 'MYLabel' + intToStr(i);
  Mylabel.Caption := 'Meine Label';
  MYLabel.Top := i * 30;
  MyLabel.OnMouseDown := Form1.OnMouseDown;
end;
  Button1.enabled := False;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var i : integer;
begin
If Sender is Tlabel then
  OBName := Tlabel(Sender).Name ;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if Shift = [ssLeft] then
  If FindComponent(OBName) is TLabel then
    with FindComponent(OBName) as TLabel do begin
      left := x;
      top := y;
    end;
end;


Gruß + Danke
HODA

(09.10.02 18:31 Tino) Code-Tags hinzugefügt.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 09.10.02 18:33 
Du musst auch eine Procedure dem OnMouseMove Event zuweisen:
ausblenden Quelltext
1:
MyLabel.OnMouseMove := Form1.OnMouseMove;					
Hoda Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Mi 09.10.02 19:46 
Hi Tino,
ja ich habe dies auch versucht, nur ein Problem ergibt sich.
Beim verschieben des Labels bekomme ich komische Effekte.

Das liegt daran das er die X,Y Werte innerhalb des Labels berücksichtigt.

Beispiel wenn die Mauskoordinaten X=100, Y=30 ist, ist es nach Mausbewegung auf dem Label X=4, Y=8. Obwohl dies nicht der Fall sein sollte.

Gruß
Hoda.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 10.10.02 09:13 
Hast Du schon mal versucht ScreenToClient und/oder ClientToScreen zu benutzen?

Gruß
TINO
Hoda Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Fr 11.10.02 09:26 
Hi Tino,
nein ich habe die beiden Funktionen nicht benutzt, aber das Problem mit "MMouse : TMouse" gelöst. Die Funktion "MMOuse.CursorPos" für die X oder Y Koordinate benutzt.

Danke für deine Hilfe. :)
Gruß
Hoda