![]() |
Navigation mit Pfeiltasten
Hallo @All,
ich mache gerade meine ersten Gehversuche mit Delphi 7. Leider habe ich bereits jetzt ein scheinbar unlösbares Problem. Ich versuche es mal zu erklären: Ich habe 4 Buttons: (1) (2) (3) (4) Ich möchte mit den Pfeiltasten Navigieren. Die Möglichkeit TabOrder kenne ich, die nützt mir aber nichts. Wenn Button (1) den Focus hat möchte ich mit der Pfeiltaste (rechts) das Button (2) den Focus bekommt oder mit Pfeiltaste (runter) das Button (3) den Focus bekommt. Ich hoffe es kann jemand HELFEN Gruß DM007 :hi: |
Re: Navigation mit Pfeiltasten
Hallo!
Eigentlich müßte das funktionieren, wenn Du TabOrder richtig setzt, die Buttons vertikal und horizontal an den Rändern an der gleichen Position ausrichtest und keine anderen Komponenten auf der Form hast. Oder Du plazierst die Buttons auf einem Panel, wenn Du andere Komponenten brauchst. Das hatt' ich vergessen: Du mußt einem Butten den Fokus geben (ActiveControl in der Form) sonst wird das nix. |
Re: Navigation mit Pfeiltasten
@Sunlight7
Vielen Dank für Deine Antwort.. Habe gleich versucht das umzusetzen, und was soll ich sagen, es geht. Das Focus setzen mit 'ActiveControl' hat es gebracht. Vielen Dank DM007 :-D |
Re: Navigation mit Pfeiltasten
Bitte gerne.
Ich kann mich noch gut Erinnern, wie ich von Basic in Delphi wechselte und man bei den einfachsten Sachen ansteht. Nicht aufgeben, es lohnt sich Delphi zu lernen! Grüße und viel Spaß mit Delphi! :coder: |
Re: Navigation mit Pfeiltasten
Sorry, aber ich muss nochmal STÖREN!
Habe nur mit 2 Buttons getestet. Ich verstehe nicht was DELPHI hier macht?
Delphi-Quellcode:
Ich habe 4 Buttons und mit der RECHTS Taste möchte ich den Focus um 1 Button weiterschalten. Mit 2 Buttons funkt das auch.
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState); begin if (Form1.ActiveControl = RzBmpButton1) and (Key = VK_RIGHT) then Form1.ActiveControl := RzBmpButton2; if (Form1.ActiveControl = RzBmpButton2) and (Key = VK_RIGHT) then Form1.ActiveControl := RzBmpButton3; if (Form1.ActiveControl = RzBmpButton3) and (Key = VK_RIGHT) then Form1.ActiveControl := RzBmpButton4; end; Aber mit 4 Buttons, springt der von der 1 auf die 4 Hä, was mache ich FALSCH??? :wall: Gruß DM007 |
Re: Navigation mit Pfeiltasten
Das liegt bestimmt daran, dass du vor der Überprüfung schon das ActiveControl neu setzt. Wenn die erste Bedingung erfüllt ist, wird RzBmpButton2 aktiv, dadurch ist sofort die 2. Bedingung erfüllt.
mach es so
Delphi-Quellcode:
if (Key = VK_RIGHT) then if (Form1.ActiveControl = RzBmpButton1) and
then Form1.ActiveControl := RzBmpButton2; else if (Form1.ActiveControl = RzBmpButton2) and (Key = VK_RIGHT) then Form1.ActiveControl := RzBmpButton3; else if (Form1.ActiveControl = RzBmpButton3) and (Key = VK_RIGHT) then Form1.ActiveControl := RzBmpButton4; |
Re: Navigation mit Pfeiltasten
Hi, und Danke für Antwort,
aber leider funktionieren Deine Angaben nicht. Gedanklich nochvollziehen kann ich das leider auch nicht. Kann das bitte nochmal jemand aufbereiten? Gruß DM007 |
Re: Navigation mit Pfeiltasten
Hi,
hier Dein alter Code etwas verändert
Delphi-Quellcode:
ungetestet, denke aber es funktioniert.
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState); begin if (Form1.ActiveControl = RzBmpButton1) and (Key = VK_RIGHT) then begin Form1.ActiveControl := RzBmpButton2; exit;//Beim erfüllen der Bedingung springt er hier aus der procedure end; if (Form1.ActiveControl = RzBmpButton2) and (Key = VK_RIGHT) then begin Form1.ActiveControl := RzBmpButton3; exit;//Beim erfüllen der Bedingung springt er hier aus der procedure end; if (Form1.ActiveControl = RzBmpButton3) and (Key = VK_RIGHT) then begin Form1.ActiveControl := RzBmpButton4; exit;//Beim erfüllen der Bedingung springt er hier aus der procedure end; end; |
Re: Navigation mit Pfeiltasten
Ich werd WAHNSINNIG, super vielen Dank. Jetzt geht es.
Ein SIMPLES 'exit' kann Wunder bewegen! Da hätte ich auch selber draufkommen können :oops: Vielen Dank NOCHMALS :thumb: DM007 |
Re: Navigation mit Pfeiltasten
Und wie wäre es in dieser Art?
Delphi-Quellcode:
case Key of
VK_RIGHT: if ActiveControl = RzBmpButton1 then ActiveControl := RzBmpButton2 else if ActiveControl = RzBmpButton3 then ActiveControl := RzBmpButton4; VK_UP: if ActiveControl = RzBmpButton3 then ActiveControl := RzBmpButton1 else if ActiveControl = RzBmpButton4 then ActiveControl := RzBmpButton2; VK_LEFT: if ActiveControl = RzBmpButton2 then ActiveControl := RzBmpButton1 else if ActiveControl = RzBmpButton2 then ActiveControl := RzBmpButton3; VK_DOWN: if ActiveControl = RzBmpButton1 then ActiveControl := RzBmpButton3 else if ActiveControl = RzBmpButton2 then ActiveControl := RzBmpButton4; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:31 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 by Thomas Breitkreuz