简体   繁体   English

C#/ WPF中TabStop上的“ DING”

[英]'DING' On TabStop in C#/WPF

I currently have a WPF window with numerous textboxes/buttons. 我目前有一个WPF窗口,其中包含许多文本框/按钮。 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. 当前,当尝试使用TAB键在对象之间导航时,您会听到“ DING” ,并且焦点不会更改为TabIndex中的下一个对象。

Here is what the window I have looks like with the TabIndex numbers displayed. 这是我所看到的窗口,其中显示了TabIndex数字。

范例图片

All the objects have TabStop set to True. 所有对象的TabStop都设置为True。

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. 然后利用此功能来抓住TAB键并处理焦点。

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. 这仍然会产生“ DING”,但焦点会改变,这是我首先要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM