Autor Beitrag
the_immortal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 78



BeitragVerfasst: Do 02.10.03 08:35 
Guten Morgen

Ich habe da eine Frage und zwar würde mich interessieren wie ich per Drag & Drop ein Shape oder ein Image verschieben kann!
maze2k
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 252

WIN 95, WIN NT 4.0, WIN 98, WIN 98SE, WIN 2000, RedHat Linux 7.3, Mandrake Linux 9.2, Knoppix Linux 3.3
D6 Pers
BeitragVerfasst: Do 02.10.03 21:08 
Ok ganz einfach...
in dein var wo auch deine TForm drin steht:

ausblenden Delphi-Quelltext
1:
2:
3:
var
  m    : TPoint;
  d    : Boolean = False;


in das MouseDown-Event des Objekts:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.DeinObjektMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  d := True;
  m.x := x;
  m.y := y;
end;


ins OnMouseMove-Event:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.DeinObjektMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
  if not d then Exit;
  self.Left := self.Left + x - m.x;
  self.Top := self.Top + y - m.y;
end;


und ins OnMouseUp:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.DeinObjektMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  d := False;
end;



Alles kloar? :)

_________________
Wer das Konzept der Unendlichkeit verstehen will, muss nur das Ausmaß menschlicher Dummheit betrachten. (Voltaire)
the_immortal Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 78



BeitragVerfasst: Di 14.10.03 08:21 
Hat bestens funktioniert, vielen Dank!

Das was ich abändern musste war, dass ich das self durch das Objekt z.B Shape1 ersetzten musste, da er sonst das ganze Form verschob :)

Gruss the_immortal
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Di 03.02.04 14:22 
Titel: hmm,
das funktioniert ganz gut aber ich hab da ein kleines Problem welches ich nicht ganz verstehe. Ich hab auch den DoubleKlick auf die Komponente belegt. Im DblClick Event hab ich dann ein d := false drin weil man die Komponente nicht bewegen will sondern die Doppelklickeigenschaft nutzen will. Trotzdem verschiebt es mir die Komponente noch wenn ich darüber fahre. Ich brauch also nicht die Maus zu drücken, eifachens drüberfahren genügt. Obwohl d auf False sitzt. Was habe ich übersehen?

_________________
mfg. Joel
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Di 03.02.04 18:48 
Titel: hmm,
hat sich erledigt, durch en doppelklick läuft er ja zweimal durch das mousedown event, das muss man einmal abfangen.

_________________
mfg. Joel