Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 15.01.07 07:13 
Weis jemand wie das geht? hab nach nem Tut und bei google gesucht aber nix gefunden.
Ich möchte ein Label per Drag 'n Drop von ner Pagecontrol auf ein Panel kopieren. (Also beim ablegen im Panel wird ein LAbel mit gleicher Caption erzeugt)

Ein Beispiel wäre nett.
Danke
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mo 15.01.07 07:43 
Morgen!

Ich würde so vorgehen:

Label nehmen (von der PageControl) und am Mauszeiger kleben lassen damit der User sieht wo er ist.
Sobald er dann das Label loslässt, prüfst entweder

a) ob sich das Label auf dem Panel befindet, sprich du prüfst, ob die Koordinaten des Labels in denen des Panels liegen oder aber
b) du prüft, ob die Mauskoordinaten im Bereich des Panels liegen.

Sollte a) oder b) eintreffen, so positionierst du einfach das Label auf dem Panel neu, oder aber du erstellst es dynamisch.

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 15.01.07 07:54 
@user profile iconZeitGeist87: Viel zu kompliziert. Delphi bietet durchaus auch selbst Drag-and-Drop-Unterstützung... ;-)

1. Beim Label DragMode auf dmAutomatic setzen.
2. In OnDragOver des Panels:
ausblenden Delphi-Quelltext
1:
  Accept := (Source is TLabel) and (Sender <> Panel1);					
Die Zuweisung von Accept auf True bzw. False sorgt dafür, dass ein Objekt an der Stelle abgelegt werden kann oder nicht, was auch am Mauscursor sichtbar ist.
3. In OnDragDrop des Panels musst du das Label neu erzeugen oder hier im Beispiel einfach dorthin verschieben:
ausblenden Delphi-Quelltext
1:
  TControl(Source).Parent := Panel1;					
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mo 15.01.07 07:58 
Och man..soviele Zeichen umsonst getippt :)

Ja spontan is mir nix besseres eingefallen..aber hätte er mal die Forensuche benutzt, würde er sicher etwas finden, was ich adaptieren lässt...

Ich gebe zu jaenicke, deine Lösung ist wohl die äquivalenteste zum Umsetzen =)

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Mo 15.01.07 08:16 
Falls du ein neues Label erstellen willst geht das so :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Panel1DragDrop(Sender, Source: TObject; X, Y: Integer);
// Erzeugt ein neues Label mit der Caption der "gedroppten" Labels
// an der aktuellen Position des Cursors
var
 newLabel: TLabel;
begin
 newLabel:=TLabel.Create(Self);
 with newLabel do
 begin
     Parent:=Form1.Panel1;
     Caption:=(Source as TLabel).Caption;
     Left:=X;
     Top:=Y;
 end;
end;
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 15.01.07 09:45 
sieht gut aus...ich prüfs gleich nachher...aber müsste gehen
danke nochmal
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 15.01.07 11:17 
gestestet...Problem: Der Sender ist das Panel! Warum?
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 15.01.07 11:32 
Ok siehe Delphi Hilfe: Sender ist das Objekt wo es abgelegt wird...
EDIT: Wie kriege ich jz den "echten" sender raus?

Dann noch ne Frage: wenn ich ein Label verschiebe (Event OnStartDrag) kann ich dann gleichzeitig 2 weitere anhängen? Also so, dass alle 3 verschoben werden und am Mauszeiger "kleben"?
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Mo 15.01.07 19:58 
Wenn du mit Sender die Komponente meinst, die du verschieben/kopieren willst dann ist das source. Siehe dazu auch mein Code weiter oben ^^
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 15.01.07 20:14 
nein bezieht sich auf den code von jaenicke...
Sender als der Ursprung des verschobenen Objekts...
Habs aber gelöst: im Startdrag event ne globale var setzen
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 15.01.07 20:20 
Du meinst, wo das gezogene Objekt vorher lag? Wie wärs in DragDrop oder DragOver mit TControl(Source).Parent bevor du das ggf. neu zugewiesen hast? ;-)
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 15.01.07 21:46 
ok...stimmt ^^