Autor Beitrag
Flash106
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Fr 23.06.06 13:04 
Hallo,

ich möchte gerne ein Panel zur Laufzeit auf dem Forumular hin und her schieben können. Wie das geht habe ich gefunden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
const  
  SC_DRAGMOVE = $F012;  
 
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;  
  Shift: TShiftState; X, Y: Integer);  
begin  
  ReleaseCapture;  
  TWinControl(Panel1).Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);  
end;


Ich möchte es aber nicht frei verschieben können sonder nur nach links oder rechts. Es sollen mehrer Panels auf dem Forumular sein in einer Reihe. Diese soll man dann in der Reihenfolge verschieben können. Wie mache ich das??

Danke!!
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 23.06.06 15:28 
Vielleicht wäre da Draggingdoch eine bessere Alternative? So auf Anhieb fällt mir da nichts Weiteres ein.
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Fr 23.06.06 15:59 
Dragging?? Was meinst du??
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Sa 24.06.06 09:40 
Nun ich meinte eher Dockingalso das Andocken/herauslösen von Bars.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 24.06.06 10:39 
Vieleicht hilft auch eine ControlBar.
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Sa 24.06.06 23:47 
und was wenn du (mal ganz imaginär siniert) den y bereich einschränkst? also in der form:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if y in [y1..y2] then 
begin  
  ReleaseCapture;  
  TWinControl(Panel1).Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);  
end;

müsste doch eigentlich funktionieren, oder? :gruebel:
:rizla:

_________________
if you have what they want - they'll find a way to take it (bruce sterling)
WOW - 10 JAHRE Mitglied beim Delphi-Forum. Wie die Zeit vergeht, Freunde.
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: So 25.06.06 16:40 
Nein, bringt nichts.

Er will ja dass man das Panel nur in y-richtungverschieben kann. y ist aber bei Panel1MouseDown ein Parameter, der den y-wert angibt, wo hingeklickt wurde. Wenn dann brächte man die y-Koordinate, von dort, wo er das Panel loslässt. Dann würds so gehen, wie du sagst.
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Mo 26.06.06 14:14 
ja eben! er weiß ja, wo auf der form die panels sind! also wenn das programm ausgeführt wird,
sind die ja noch da, wo er sie zur designzeit platziert hat! das heißt, er kann dann mit
ausblenden Quelltext
1:
if y in [panel_top..panel_top+panel.height] then					

das panel in der horizontalen verschieben.
das panel_top muss natürlich vorher festgelegt werden, als konstante oder so.
hmm.. who knows

:rizla:

_________________
if you have what they want - they'll find a way to take it (bruce sterling)
WOW - 10 JAHRE Mitglied beim Delphi-Forum. Wie die Zeit vergeht, Freunde.
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Mo 26.06.06 15:00 
Ich fürchte ich versteh dich nicht rizla.

Wenn die Panels schon mal verschoben wurden, in x-richtung und man dann draufklickt, dann kommt das Ereignis OnMouseDown. der Parameter y gibt an, wo auf das Panel auf der y-achse geklickt wurde. aber das ereignis OnMouseDown wird ja nur einmal ausgelöst, nämlich beim draufklicken. Wenn ers dann verschiebt, was hatt dann y mit der neuen position zu tun?
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 26.06.06 15:03 
Ich hab mir da mal selber was gebastelt. Ist wahrscheinlich furchtbar kompliziert, unübersichtlich und aufwendig, aber es klappt. Ich habe statt eines Panels einen Button. Den ganzen Kram kann man entsprechend für oben/unten oder links/rechts verschieben anpassen.

Den Cursor sperre ich bei dem Drag&Drop-Vorgang ein, damit er nicht durch zu schnelles bewegen der Maus aus dem Button herausbewegt werden kann, was zu unerwünschten Effekten führen kann.
ausblenden Delphi-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:
// Mit dem Draggen anfangen und den Cursor einsperren
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var AREct: tRect;
begin
  with Button1 do Begindrag(false);
  ARect.TopLeft :=  ((Button1.Parent).ClientToScreen(Point(Button1.Left, Button1.Top)));
  ARect.BottomRight :=  ((Button1.Parent).ClientToScreen(Point(Button1.Left + Button1.Width, Button1.Top + Button1.Height)));
  ClipCursor(@Arect);
end;

// Im DragOver muss der Button verschoben werden und der Cursor-Bereich aktualisiert werden.
procedure TForm1.Button1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
Var AREct: TRect;
begin
  Button1.Left := Button1.Left + x - 37// Die 37 ist die Mitte des Buttons
  // Für größere Panels ist es evtl. besser, im OnMouseDown sich das X zu merken (z.B. im Tag des Buttons)
  // und diesen Wert dann hier verwenden.
  ARect.TopLeft :=  ((Button1.Parent).ClientToScreen(Point(Button1.Left, Button1.Top)));
  ARect.BottomRight :=  ((Button1.Parent).ClientToScreen(Point(Button1.Left + Button1.Width, Button1.Top + Button1.Height)));
  ClipCursor(@Arect);
end;

// Cursor wieder freisetzen
procedure TForm1.Button1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  ClipCursor(NIL);
end;

_________________
We are, we were and will not be.
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Mo 26.06.06 15:11 
ziemlich genial