![]() |
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; |
Re: Navigation mit Pfeiltasten
Hi,
auch nicht schlecht, Vielen Dank. Gruß DM007 |
Re: Navigation mit Pfeiltasten
Du kannst das natürlich auch noch beliebig erweitern...
z.B: 1 > 2 > 3 > 4 > 1 > ...
Delphi-Quellcode:
1 > 2 > 1 > ...
VK_RIGHT:
if ActiveControl = RzBmpButton1 then ActiveControl := RzBmpButton2 else if ActiveControl = RzBmpButton2 then ActiveControl := RzBmpButton3 else if ActiveControl = RzBmpButton3 then ActiveControl := RzBmpButton4 else if ActiveControl = RzBmpButton4 then ActiveControl := RzBmpButton1; und 3 > 4 > 3 > ...
Delphi-Quellcode:
VK_RIGHT:
if ActiveControl = RzBmpButton1 then ActiveControl := RzBmpButton2 else if ActiveControl = RzBmpButton2 then ActiveControl := RzBmpButton1 else if ActiveControl = RzBmpButton3 then ActiveControl := RzBmpButton4 else if ActiveControl = RzBmpButton4 then ActiveControl := RzBmpButton3; |
Re: Navigation mit Pfeiltasten
generisch, das wort heißt generisch!
Delphi-Quellcode:
;)
var ControlIndex: Integer; //global, am besten mit 0 initialisieren
procedure TForm1.KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var Controls: array of TControl; begin if not ((Key = VK_LEFT) or (Key = VK_RIGHT)) then Exit; //wir wollen ja nicht alles abwürgen //die zuweisung sollte man natürlich auch global machen Setlength(Controls,4); Controls[0] := Btn1; Controls[1] := Btn2; Controls[2] := Btn3; Controls[3] := Btn4; case Key of VK_RIGHT: Inc(ControlIndex); VK_LEFT: Dec(ControlIndex); end; if ControlIndex < low(Controls) then ControlIndex := high(Controls) else if ControlIndex > high(Controls) then ControlIndex := low(Controls); ActiveControl := Controls[ControlIndex]; end; [edit=SirThornberry]Quelltext auf Wunsch korrigiert - Mfg, SirThornberry[/edit] |
Re: Navigation mit Pfeiltasten
Hallo,
Zitat:
VK_LEFT und VK_UP wie VK_TAB + VK_SHIFT (rückwärts entsprechend TabOrder) VK_RIGTH und VK_DOWN wie VK_TAB Also, Deine Buttons:
Code:
der Button 4 hat den Focus, du drückst die Taste Rechts.
---------------------------
| Button1 | Button12 | | Taborder 0 | Taborder 1 | --------------------------- | Button3 | Button14 | | Taborder 2 | Taborder 3 | --------------------------- Wenn es keinen TabOrder höher als den von Button4 (TabOrder 3) gibt, wird der Focus zu dem Button mit TabOrder 0 gesetzt, eben Button1. Welches Element soll denn den Focus bekommen wenn Button 4 den Focus und Taste Rechts betätigt wird? Noch eine Anmerkung: Im OnKeyDown der Form wird von ActiveControl das Element angegeben das den Focus bekommen hat. @DGL-luke Die Variable ControlIndex muss dann aber auch bei allen Focus-Änderung durch z.B. Mausklicks, Tab ... neu gesetzt werden. |
Re: Navigation mit Pfeiltasten
Hallo DGL-luke,
bitte korrigiere Deinen Beitrag: Zitat:
Dieses Verfahren ist meiner Ansicht nach das beste, weil es beliebig viele - auch unterschiedliche - Controls verarbeiten kann. Jürgen |
Re: Navigation mit Pfeiltasten
@Lannes,Jürgen: right.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:56 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