Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Fokus auf Form1 setzen (https://www.delphipraxis.net/155948-fokus-auf-form1-setzen.html)

funky 14. Nov 2010 18:16

AW: Fokus auf Form1 setzen
 
Da muss nichtmal etwas drinstehen:

Jetzt habe ich mal folgendes rein gemacht:

[CODE?Delphi]procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('Test');
end;[/CODE]

Edit:
Also so sieht das Formular aus:
http://www.imgupload.org/images/32_qwertz.png

DeddyH 14. Nov 2010 18:22

AW: Fokus auf Form1 setzen
 
Stimmt, KeyDown geht dann nicht mehr. Nimm stattdessen doch KeyPress und WASD, das sollte das Einfachste sein ;)

funky 14. Nov 2010 18:25

AW: Fokus auf Form1 setzen
 
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.

DeddyH 14. Nov 2010 18:26

AW: Fokus auf Form1 setzen
 
Weil Du vermutlich nicht die Shift-Taste drückst. Wandle doch den Key zunächst in LowerCase oder Uppercase um, dann kannst Du besser vergleichen.

funky 14. Nov 2010 18:40

AW: Fokus auf Form1 setzen
 
Oh ja. Hast recht.
Jetzt funktioniert es wie es sein soll.
Danke

Hawkeye219 15. Nov 2010 11:15

AW: Fokus auf Form1 setzen
 
Hallo,

wenn man das Ereignis Delphi-Referenz durchsuchenOnShortCut des Formulars verwendet, dann lassen sich die Pfeiltasten abfragen - auch ohne gesetztes KeyPreview.

Gruß Hawkeye


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:52 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz