![]() |
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: ![]() |
AW: Fokus auf Form1 setzen
Stimmt, KeyDown geht dann nicht mehr. Nimm stattdessen doch KeyPress und WASD, das sollte das Einfachste sein ;)
|
AW: Fokus auf Form1 setzen
Habe es jetzt so gemacht:
Delphi-Quellcode:
Jetzt reagiert er allerdings gar nicht mehr auch wenn ich keine Buttons mehr habe.
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; |
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.
|
AW: Fokus auf Form1 setzen
Oh ja. Hast recht.
Jetzt funktioniert es wie es sein soll. Danke |
AW: Fokus auf Form1 setzen
Hallo,
wenn man das Ereignis ![]() Gruß Hawkeye |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:52 Uhr. |
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