Thema: Delphi Fokus auf Form1 setzen

Einzelnen Beitrag anzeigen

funky

Registriert seit: 14. Nov 2010
15 Beiträge
 
#13

AW: Fokus auf Form1 setzen

  Alt 14. Nov 2010, 18:25
Habe es jetzt so gemacht:

Delphi-Quellcode:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin


    if (Key = 'W') then
  begin
     if (arFelder[PosY-1,PosX] = 0) or (arFelder[PosY-1,PosX] = 2) then
     begin
        PosY := PosY-1;
        Image1.Canvas.Brush.Color:= clYellow;
        Form1.Image1.canvas.Rectangle(PosX * Abstand, PosY * Abstand, Abstand + (PosX * Abstand),
        Abstand + (PosY * Abstand));

           if arFelder[PosY,PosX] = 2 then
           begin
            ShowMessage('Sieg!')
           end;

     arFelder[PosY,PosX] := 4;
     end;

  end



   else if (Key = 'S') then
  begin
     if (arFelder[PosY+1,PosX] = 0) or (arFelder[PosY+1,PosX] = 2) then
     begin
        PosY := PosY+1;
        Image1.Canvas.Brush.Color:= clYellow;
        Form1.Image1.canvas.Rectangle(PosX * Abstand, PosY * Abstand, Abstand + (PosX * Abstand),
        Abstand + (PosY * Abstand));

           if arFelder[PosY,PosX] = 2 then
           begin
            ShowMessage('Sieg!')
           end;

     arFelder[PosY,PosX] := 4;
     end;

  end



    else if (Key = 'D') then
  begin
     if (arFelder[PosY,PosX+1] = 0) or (arFelder[PosY,PosX+1] = 2) then
     begin
        PosX := PosX+1;
        Image1.Canvas.Brush.Color:= clYellow;
        Form1.Image1.canvas.Rectangle(PosX * Abstand, PosY * Abstand, Abstand + (PosX * Abstand),
        Abstand + (PosY * Abstand));

           if arFelder[PosY,PosX] = 2 then
           begin
             ShowMessage('Sieg!')
           end;

     arFelder[PosY,PosX] := 4;
     end;

  end



   else if (Key = 'A') then
  begin
     if (arFelder[PosY,PosX-1] = 0) or (arFelder[PosY,PosX-1] = 2) then
     begin
        PosX := PosX-1;
        Image1.Canvas.Brush.Color:= clYellow;
        Form1.Image1.canvas.Rectangle(PosX * Abstand, PosY * Abstand, Abstand + (PosX * Abstand),
        Abstand + (PosY * Abstand));

           if arFelder[PosY,PosX] = 2 then
            begin
             ShowMessage('Sieg!')
            end;

     arFelder[PosY,PosX] := 4;
     end;

  end

end;
Jetzt reagiert er allerdings gar nicht mehr auch wenn ich keine Buttons mehr habe.

Geändert von mkinzler (14. Nov 2010 um 18:41 Uhr) Grund: Code-Tag durch Delphi-Tag ersetzt
  Mit Zitat antworten Zitat