Autor Beitrag
MartinBush
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Sa 05.07.08 15:27 
Hi,

für eine PocketPC Apllikation habe ich ein Keyboard angeschlossen und möchte mit den Pfeiltasten in einer Form navigieren. Das klappt auch supper.

Ich möchte nun allerding das Event genau abfragen. Also auf die linke Taste (Keys.Left) und die rechte Keys.Right reagieren. Aber was ist das für ein Event - es wird ja eine Navigation ausgelöst und hat keinen wirklichen Rückgabewert. Es ist kein KeydownEvent und kein Keypress event - beides mal wir meine Methode nicht angesprungen.

Wie kann ich rausfinden was für ein Event das ist? (P.S. Die methoden funktionieren sonst super bei Buchstaben, Zahlen und Sonerzeichen).


ausblenden C#-Quelltext
1:
2:
3:
4:
        /*private void f_top_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {

...}

Ich hatte schon bedenken das es an der Tastatur liegt aber ich kann ja mit den Tasten schon navigieren (wie Tab Taste) - auch die Pfeiltasten der internen Tastatur lüsen kein KeyEvent aus.


Mfg Martin
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 05.07.08 16:09 
Hallo!

Tipp: Die Doku ist nicht nur dazu da, um Speicher zu verbrauchen ;-)

In der steht zu jedem der Key*-Events folgendere Absatz:
Zum Beispiel beim KeyDown-Event hat folgendes geschrieben:
Key events occur in the following order:

KeyDown
KeyPress
KeyUp

To handle keyboard events only at the form level and not enable other controls to receive keyboard events, set the KeyPressEventArgs..::.Handled property in your form's KeyPress event-handling method to true. Certain keys, such as the TAB, RETURN, ESCAPE, and arrow keys are handled by controls automatically. To have these keys raise the KeyDown event, you must override the IsInputKey method in each control on your form. The code for the override of the IsInputKey would need to determine if one of the special keys is pressed and return a value of true.


Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
MartinBush Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Sa 05.07.08 19:00 
Oh ich dachte die wäre nur für Anfänger :P Daran hab ihc nicht gedacht - ich dachte evtl an ne Funktion u8m so etwas auszulesen. ZB die events die getriggert werden.

IsInputKey hab ich net gefunden also hab ich OnKeyDown genommen und meiner Button Klasse hinzugefügt.
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
    protected override void OnKeyDown(KeyEventArgs e)
        {
                switch (e.KeyCode)
                {
                    case Keys.Left:
                    case Keys.Right:
                        e.Handled = true;
                        break;
                }
                base.OnKeyDown(e);
         }

Und dann

      private  void f_top_KeyDown(object sender, KeyEventArgs e)
       
            {
                if (e.KeyCode == Keys.Left)
                {
                    ...
                }
                else if (e.KeyCode == Keys.Right)
                {
                   ...
                }
            }

Im Designer habe ich

            this.KeyPreview = true;
            this.f_top.KeyDown += new System.Windows.Forms.KeyEventHandler(this.f_top_KeyDown);


Ich dachte das das klappt - mit Workaround bekomm ichs hin aber so nicht - was habe ich nicht verstanden?


Dank dir
MartinBush Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Mo 07.07.08 14:22 
Error 1 .. .IsInputKey(System.Windows.Forms.Keys)': no suitable method found to override

Kann die Methode nicht überschreiben - was mache ich nun?
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mo 07.07.08 14:31 
Wenn es die Methode im Compact Framework nicht gibt, gibt es möglicherweise einfach überhaupt keine Lösung, zumindest vom Framework aus.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 07.07.08 14:32 
Hm, gibt's das vielleicht beim Compact Framework nicht :gruebel:

Versuch mal, ob das KeyUp-Ereignis ausgelöst wird. Das wird manchmal auch dann ausgelöst, wenn die anderen Events zu faul sind ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
MartinBush Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Mo 07.07.08 15:05 
Habe jetzt noch ein Klasse erstellt und dort die Virtuelle Methode IsinPutKey


ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
      class Button2 : Button

    {
        protected virtual bool IsInputKey(System.Windows.Forms.Keys keyData)
        {
            return true;
        }
    
    }


Meine Buttonklasse leitet sich dann von Button2 ab anstatt von Button. Nun kann ich die Methode auch überschreiben - aber es klappt noch nicht.


Zitat:
set the KeyPressEventArgs..::.Handled property in your form's KeyPress event-handling method to true.

Wie mache ich das?