Autor Beitrag
Robii
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236



BeitragVerfasst: Sa 19.09.09 13:46 
Guten Tag, ich hab folgenden Code geschrieben:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
var
a: TPoint;
begin
a:=Mouse.CursorPos;
Shape1.Left := Round(a.x-Shape1.Width/2);
Shape1.Top := Round(a.y-Shape1.Height/2);


Wenn ich jetzt den Timer aktiviere, folgt das Shape zwar der Maus, aber nicht genau unter der Maus, sondern um ein großes Stück nach rechts unten verschoben. Wieso?
Grüße.


Moderiert von user profile iconGausi: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Sa 19.09.2009 um 14:28
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 19.09.09 14:27 
Weil CursorPos die globalen Screenkoordinaten der Maus bestimmt, nicht die Koordinaten auf deiner Form/Panel/Sonstwas. Das musst du dann umrechnen lassen:
ausblenden Delphi-Quelltext
1:
a := [Control auf dem die Maus ist].ScreenToClient(Mouse.CursorPos);					

_________________
We are, we were and will not be.
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Mo 21.09.09 20:04 
Ja, da hat user profile iconGausi recht...
Damit das Shape denn genau unter der Maus laufen würde, müsstest Du Dein Fenster wirklich auf Vollbild (also so, wie wenn man sich Videos auf dem Rechner anguckt) machen.
So müsstest Du das dann immer in etwa so rechnen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var a: TPoint;
begin
a:=Mouse.CursorPos;
Shape1.Left := Round(a.x-Shape1.Width/2)-FormFolgeDerMaus.Left;
Shape1.Top := Round(a.y-Shape1.Height/2)-FormFolgeDerMaus.Top;

Eigentlich müsstest Du dann aber auch noch die Fenstertitel-leistenhöhe abziehen - dann müsste es in etwa hinkommen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 21.09.09 20:20 
Und was, wenn das Shape auf einem Panel ist, was nicht bei 0/0 anfängt? ;-)

Für sowas ist die ScreenToClient-Funktion da.

_________________
We are, we were and will not be.