Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Navigation mit Pfeiltasten (https://www.delphipraxis.net/77395-navigation-mit-pfeiltasten.html)

dm007 19. Sep 2006 03:03


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:

Sunlight7 19. Sep 2006 04:06

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.

dm007 19. Sep 2006 13:02

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

Sunlight7 19. Sep 2006 16:03

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:

dm007 20. Sep 2006 04:19

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:
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;
Ich habe 4 Buttons und mit der RECHTS Taste möchte ich den Focus um 1 Button weiterschalten. Mit 2 Buttons funkt das auch.
Aber mit 4 Buttons, springt der von der 1 auf die 4 Hä, was mache ich FALSCH??? :wall:

Gruß DM007

rayman 20. Sep 2006 04:39

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;

dm007 20. Sep 2006 12:19

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

uwewo 20. Sep 2006 12:33

Re: Navigation mit Pfeiltasten
 
Hi,

hier Dein alter Code etwas verändert

Delphi-Quellcode:
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;
ungetestet, denke aber es funktioniert.

dm007 20. Sep 2006 12:56

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

himitsu 20. Sep 2006 13:22

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 21:19 Uhr.
Seite 1 von 2  1 2      

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