Autor Beitrag
neo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 179



BeitragVerfasst: Mi 26.03.03 09:32 
Hallo!

Ich habe ein Shape erstellt, welches ich mit den Pfeiltasten über den Bildschirm steuern kann.

Wie kann ich erreichen, dass sobald ich über die Form hinausfahre (Scrollbars kommen dann), das Shape sozusagen in die Richtung blockiere?

(Es soll nur in der Form steuerbar sein, nicht darüber hinaus)

Danke!
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mi 26.03.03 09:57 
Also wenn Du das über die Steuertasten machst, dann würde ich Dir empfehlen, einfach abzufragen, ob der rechte Rand darüber hinausgeht, also
ausblenden Quelltext
1:
2:
if Shape1.Left+Shape1.Width>=ClientWidth then
   {hier dann nichmehr bewegen, z.B. mit Exit die Prozedur verlassen}


Analog machst Du das dann mit Top+Height>=ClientHeight, Left<=0 und Top<=0

Dann dürfte das eigentlich funktionieren. Jemand irgendwelche Einwände? *g*[/code]
neo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 179



BeitragVerfasst: Mi 26.03.03 18:03 
Titel: Re:
so habe ich das schon probiert, wenn ich allerdings die 2. Seite deffiniere, über die das Sahpe nicht hinübergehen darf, kann man wieder über die erste....

*Keine Ahnung warum*
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mi 26.03.03 18:13 
Poste mal ein bisschen COde, dann kann ich Dir vll. besser helfen
neo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 179



BeitragVerfasst: Do 27.03.03 13:18 
Titel: RE:
So hier der Quellcode:

ausblenden volle Höhe 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:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
var
  Form1: TForm1;
  Keys: Array[0..255] of Boolean;

//Var deklariert

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  Keys[Key]:=true;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  Keys[Key]:=false;
end;

//Jetzt ein Timer welcher alle paar Milllisekunden prüft ob eine Taste gedrückt worden ist

procedure TForm1.timObenTimer(Sender: TObject);
begin
        if Shape1.Top=0 then
        begin
        if Keys[VK_down] then
        Shape1.Top:=Shape1.Top+5;

        if Keys[vk_left] then
        Shape1.Left:=Shape1.left-5;

        if Keys[vk_right] then
        Shape1.Left:=Shape1.left+5;
        end
        else
        begin
        if Keys[VK_down] then
        Shape1.Top:=Shape1.Top+5;

        if Keys[vk_left] then
        Shape1.Left:=Shape1.left-5;

        if Keys[vk_right] then
        Shape1.Left:=Shape1.left+5;

        if Keys[vk_up] then
        Shape1.Top:=Shape1.top-5;
        end;
end;


So das war der Code. Wenn ich jetzt noch eine Bedingung stelle (wenn das shape unten ankommt, wird die funktion die richtung oben blockieren soll wenn shape1.top=0 wieder aufgehoben...[/code]
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 27.03.03 13:34 
Hab mir Deinen Code jetzt mal zu Herzen genommen *g*.

Folgendermaßen hab ich Deinen Timer-Code verändert:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if (Keys[VK_down]) AND (Shape1.Top+Shape1.Height<=ClientHeight) then
      Shape1.Top:=Shape1.Top+5;
if (Keys[vk_left]) AND (Shape1.Left>=0) then
      Shape1.Left:=Shape1.left-5;
if (Keys[vk_right]) AND (Shape1.Left+Shape1.Width<=ClientWidth)then
      Shape1.Left:=Shape1.left+5;
if (Keys[vk_up]) AND (Shape1.Top>=0) then
      Shape1.Top:=Shape1.top-5;


Das funktioniert so auch, nur ist das Problem mit den 5er-Schritten, dass es dann sein kann, dass er dann unten und rechts Scrollbalken anzeigt, weils über den Rand hinausgeht, die solltest Du ausschalten, oder eben mit 1er-Schritten arbeiten und das Timer-Intervall verkürzen.

Dein Array ist auch etwas groß, aber darüber kann ich mich jetzt im Moment nicht mehr auslassen :wink:. So wie's jetzt da steht funktionierts auf jeden Fall.

Gruß