Autor Beitrag
Zlatan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 25.01.11 16:23 
Ich habe ein Shape, dass ich mit Hilfe der Pfeiltasten bewegen kann,
allerdings bis ins unendliche
Meine Idee :idea: : Begrenzungen aus Shapes eine Art Wand
Geht das?
Wie mache ich das dann?


Moderiert von user profile iconGausi: Topic aus Sonstiges (Delphi) verschoben am Di 25.01.2011 um 16:05
MaxWurzel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 77
Erhaltene Danke: 10



BeitragVerfasst: Di 25.01.11 16:32 
Du könntest vor dem Verschieben abfragen, ob das Shape bereits an der entsprechenden Grenze liegt.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case key of
    VK_Left:  if shape1.Left >160 then shape1.Left := shape1.Left -1;
    VK_Right: if shape1.Left <180 then shape1.Left := shape1.Left +1;
    VK_Up:    if shape1.Top >350  then shape1.Top := shape1.Top -1;
    VK_Down:  if shape1.Top <370  then shape1.Top := shape1.Top +1;
  end;
end;
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 25.01.11 16:34 
Das verstehe ich jetzt nicht es gibt ja keine Grenze die Form endet irgendwann
das shape kaann aber immer weiter zB nach links
MaxWurzel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 77
Erhaltene Danke: 10



BeitragVerfasst: Di 25.01.11 16:37 
Deine Idee war doch eine Art Wand zu bauen. Das machst du indem du die Werte left und top für das shape eingrenzt. Im Beispiel: 160 <= left <= 180, 350 <= top <= 370.
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 25.01.11 16:38 
heißt das dann wenn ich an die Grenze komme das Shape automatisch einen zurück "geworfen" wird
Deine Idee funktioniert leider nicht
Habe es gerade ausprobiert das Shape geht außerhalb der Form
Zwar erscheint jetzt eine Scrollbar aber das Shape hat keine Grenze


Zuletzt bearbeitet von Zlatan am Di 25.01.11 16:42, insgesamt 1-mal bearbeitet
MaxWurzel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 77
Erhaltene Danke: 10



BeitragVerfasst: Di 25.01.11 16:39 
Nein, es passiert einfach nichts.
HenryHux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 542
Erhaltene Danke: 33

Windows 7 Premium
Delphi XE, Eclipse
BeitragVerfasst: Di 25.01.11 16:42 
Das wird daran liegen, dass die Maße die er als Beispiele genommen hat, deinen nicht entsprechen.
Spiele doch einfach mal ein bisschen mit den Zahlen rum.
So müsstest du es aber auf die Form limitieren können, sodass es nicht "rausspringt".
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case key of
    VK_Left:  if shape1.Left < Form1.left then shape1.Left := shape1.Left -1;
    VK_Up:    if shape1.Top < Form1.Top  then shape1.Top := shape1.Top -1;
// geht auch mit right und down
  end;
end;

Für diesen Beitrag haben gedankt: Zlatan
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 25.01.11 16:44 
das Shape soll an einem anderen Shape quasi hängen bleiben
Also trotz nach links drücken nicht weiter nach links gehen
Eben wie eine wand
HenryHux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 542
Erhaltene Danke: 33

Windows 7 Premium
Delphi XE, Eclipse
BeitragVerfasst: Di 25.01.11 16:46 
Naja, genau dafür kannst du die Ifs benutzen.
Zb :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
 
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case key of
    VK_Right:  if shape1.Left+shape1.width < Shape2.left then shape1.Left := shape1.Left -1;  //bewirkt, dass es sich von links nicht weiter bewegt als zur grenze des zweiten shapes
    //...
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 25.01.11 16:55 
Das funktioniert leider nicht
Das Shape geht einfach durch die anderen Shapes hindurch

Meine Form sieht soo aus: ein viereck aus recheckigen shapes
und in der Mitte das rundes Shape
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 25.01.11 17:04 
user profile iconZlatan hat folgendes geschrieben Zum zitierten Posting springen:
Das funktioniert leider nicht

Dann machst du was falsch.

Wie wäre es, wenn du mal zeigst, wie du es probiert hast, damit hier das Rumgerate aufhören kann?

_________________
We are, we were and will not be.
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 25.01.11 17:07 
Nicht gleich wütend werden :evil:
vielleicht mache ich ja was falsch oder wir reden aneinander vorbei


Was genau braucht ihr für Infos?


Ich habe meine Form erklärt.
Dann habe ich den den oben genannten quelltext kopiert und bei mir eingefügt
das runde und bewegbare Shape geht aber unter die anderen shapes hindurch


Warum antwortet keiner mehr??? :(
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 25.01.11 17:40 
Hier ist keiner wütend.

Aber wenn du hier immer nur postest "Das klappt nicht", dann kann man dir nicht weiterhelfen.

Wenn du den Code (ich meine den letzten von HenryHux) kopiert hast, dann wirst du vermutlich festgestellt haben, dass ein Druck auf rechts das Shape nach links bewegt. Wenn man das passend korrigiert, funktioniert es. :nixweiss:

_________________
We are, we were and will not be.
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 25.01.11 17:44 
sorry wollte nicht streit auslösen.
Ich versuche es jetzt noch mal
so ich habe das kopiert(mit if...) aber der Punkt geht durch das rechteckige Shape durch

und wenn ich rechts drücke geht das shape auch nach rechts
Vielleicht hilft mein Text ja weiter:
ausblenden volle Höhe 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:
30:
31:
32:
33:
34:
35:
36:
37:
38:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
case key of
    VK_Left: shape1.Left := shape1.Left -10;
    VK_Right: shape1.Left := shape1.Left +10;
    VK_Up: shape1.Top := shape1.Top -10;
    VK_Down: shape1.Top := shape1.Top +10;
  end;

end;
end.
das ist aber ohne das Eingefügte

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
HenryHux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 542
Erhaltene Danke: 33

Windows 7 Premium
Delphi XE, Eclipse
BeitragVerfasst: Di 25.01.11 18:10 
So ok, vielleicht sollten wir es mal erklären, bevor es nur Fehler beim Copy/Pasten gibt.

Erst einmal mit Delphi-Tags:
ausblenden volle Höhe 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:
30:
31:
32:
33:
34:
35:
36:
37:
38:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
case key of
    VK_Left: shape1.Left := shape1.Left -10;
    VK_Right: shape1.Left := shape1.Left +10;
    VK_Up: shape1.Top := shape1.Top -10;
    VK_Down: shape1.Top := shape1.Top +10;
  end;

end;
end.


So.
Das sollte bis jetzt soweit ja ganz gut klappen.
Angenommen du willst, wenn du rechts drückst, dass er nach rechts geht, aber nicht wenn er eine andere Shape überschreitet.
Was musst du dafür tun?
Genau, die Positionen von beiden Shapes kennen.
Da du dein Shape nur unter einer bestimmten Bedingung bewegen willst, nimmst du schonmal eine If Struktur.
Grob so :  VK_Right: If ... then shape1.Left := shape1.Left +10;
Was jetzt als Bedingung geben?
Dafür musst du jetzt die Position von Shape1 haben. Da du nach rechts bewegst, brauchst du davon die rechte Position = Links+Breite.
ausblenden Delphi-Quelltext
1:
VK_Right: If Shape1.Left + Shape1.width ... then shape1.Left := shape1.Left +10;					

Jetzt die Linke Position des 2ten Shapes:
ausblenden Delphi-Quelltext
1:
VK_Right: If Shape1.Left + Shape1.width < Shape2.Left - 10 then shape1.Left := shape1.Left +10					

So müsstest du es für alle Richtungen machen. Das -10 ist hier übrigens reingefügt, da sich die Shapes sonst teilweise überschneiden können.

Lg
Zlatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175



BeitragVerfasst: Di 25.01.11 18:18 
Danke,
muss ich für left und width in deinem quelltext die richtigen zahlen einfügen?
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Di 25.01.11 18:19 
user profile iconZlatan hat folgendes geschrieben Zum zitierten Posting springen:
Danke,
muss ich für left und width in deinem quelltext die richtigen zahlen einfügen?


ohne worte...

dafür mit Hinweis auf Tutorials:
Christians Crashkurs
Delphi-Wikibook

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.