![]() |
Delphi-Version: 5
Fokus auf Form1 setzen
Hi,
Also bin neu hier und ich weis der Titel sagt einigen erstmal nix. Mein Problem ist folgender: Ich habe ein Spielfeld(Image1) und einen Button1 mit dem auf Image1 das Spielfeld und die Figur gezeichnet werden. Jetzt habe ich bei "FormKeyDown" die Tastenabfrage rein gemacht, also wenn man die Pfeiltaste nach oben drückt soll sich die Figur nach oben bewegen. Allerdings geht das nicht. Sobald ich auf Button1 klicke reagiert das Programm nicht auf die Tastenabfrage wie es soll. Ich könnte bei Button1 unter "OnKeyDown" dasselbe wie bei "FormKeyDown" reinmachen. Dann funktioniert es auch. Da habe ich dann aber auch wieder das Problem, dass ich es bei jedem Button, dass ich in das Formular reinmache den Code reinmachen muss und dann ist der Code nur unnötig lang/unsauber. Ich hoffe ihr habt verstanden wo mein Problem liegt. MfG funky |
AW: Fokus auf Form1 setzen
Setz mal die Eigenschaft KeyPreview der Form auf true.
|
AW: Fokus auf Form1 setzen
Hallo,
versuche mal "KeyPreview" des Formulars auf "true" zu setzen (entweder per Code oder im OI). Güße Matze Edit: Och Mensch, Deddy ... Edit 2: Dass der Beitrag nicht ganz umsonst ist: Herzlich Willkommen in der DP, funky! |
AW: Fokus auf Form1 setzen
[OT] Der Turbo-Opa hat wieder zugeschlagen :lol: :zwinker: [/OT]
|
AW: Fokus auf Form1 setzen
Nein funktioniert nicht.
Sobald ich einen Button auf mein Formular setze reagiert er nicht mehr auf meine Tastenabfrage. Edit: Ich weis nicht ob das was bringt aber ich benutze "Embarcadero RAD Studio 2010" |
AW: Fokus auf Form1 setzen
Das mag ich nicht recht glauben.
|
AW: Fokus auf Form1 setzen
Was magst du nicht glauben? oO
Soll ich dir meine Projektdateien schicken? |
AW: Fokus auf Form1 setzen
Zeig doch einfach mal den Quelltext(den relevanten Teil).
|
AW: Fokus auf Form1 setzen
Also das ist der Teil wo er die Figur bewegt oder eben nicht bewegt:
Delphi-Quellcode:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); begin if (Key = VK_UP) 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 = VK_Down) 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 = VK_Right) 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 = VK_Left) 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; Und dann ist da noch der Teil wo das Spielfeld gezeichnet wird. |
AW: Fokus auf Form1 setzen
Und was steht im OnClick des Buttons?
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:09 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