1
votes

I currently have a WPF window with numerous textboxes/buttons. Currently when trying to use the TAB key to navigate between the objects you hear a 'DING' and the focus is not changed to the next object in the TabIndex.

Here is what the window I have looks like with the TabIndex numbers displayed.

Example Image

All the objects have TabStop set to True.

1

1 Answers

0
votes

Not the prettiest solution but it works.

On Form Initialization call

this.KeyUp += new System.Windows.Forms.KeyEventHandler(KeyEvent);

Then utilize this function to grab the TAB key and process the focus.

private void KeyEvent(object sender, KeyEventArgs e) //Keyup Event 
    {
        if (e.KeyCode == Keys.Tab)
        {
            ++iFocusCount;
        }
        else if (e.KeyCode == Keys.Tab && e.KeyCode == Keys.Shift)
        {
            --iFocusCount;
        }
        switch (iFocusCount)
        {
            case 0:
                contactBox.Focus();
                break;

            case 1:
                incidentBox.Focus();
                break;
            case 2:
                actionsListBox.Focus();
                break;
            case 3:
                profilesListBox.Focus();
                break;
            case 4:
                currentLatchBox.Focus();
                break;
            case 5:
                daysBox.Focus();
                break;
            case 6:
                calculateDateButton.Focus();
                break;
            case 7:
                copyButton.Focus();
                break;
            case 8:
                notesTextBox.Focus();
                break;
            case 9:
                keycodeBox.Focus();
                break;
            case 10:
                xnaBox.Focus();
                break;
            case 11:
                generateTamButton.Focus();
                break;
            case 12:
                generateNotesButton.Focus();
                break;
            case 13:
                sendEmailButton.Focus();
                break;
            case 14:
                saveButton.Focus();
                break;
            case 15:
                clearLabel.Focus();
                break;
            case 16:
                iFocusCount = 0;
                contactBox.Focus();
                break;
        }

    }

This still produces the "DING" but the focus changes which is what I wanted in the first place.