Tab will not fire keydown or keypress event

偶尔善良 提交于 2019-12-11 20:44:11

问题


I am working in a webform and have a form with a tab bar on it. Each tab has multiple text boxes in it. I have the tab indexes incremented, starting with 1 for each tab. I want to tab from tab to tab if the user hits the end of the form and hits tab.

I used the leave method and changed the tabs for my tab control the only problem is if I didn't hit tab and say I click to another control on that tab it will still shoot over to the new tab.

I figure a way to solve this would be to listen for the tab key press and if the key press is tab on leave then change the form to the other tab, I just can't seem to get it to work though. I have tried with keypress and keydown but neither will pick up that tab as a key. If I was to say click or hit start typing it will trigger the events but tab will not.

Any suggestions?

I have tried these and none of these event would even trigger.

private void afsiTxtDaysForTempOEpriceOverrides_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 11)
        {
            afsiTxtDaysForTempOEpriceOverrides_Leave(sender, e);
        }
    }

private void afsiTxtDaysForTempOEpriceOverrides_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == "11")
    {
        afsiTxtDaysForTempOEpriceOverrides_Leave(sender, e);
    }
}

private void afsiChkSalesBaseCostUpdate_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 11)
    {
        afsiChkSalesBaseCostUpdate_Leave(sender, e);
    }
}

private void afsiChkSalesBaseCostUpdate_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == 11)
    {
        afsiChkSalesBaseCostUpdate_Leave(sender, e);
    }
}

EDIT: Found out that the page is using UltraWinTabControl from Infragistics so maybe this is causing some issues with the tabbing.


回答1:


I ended up needing to override ProcessCmdKey now I face a new problem that is kind of related but not particular to this so I will add it as a comment if I get my answer.

    private bool isTab = false;
    private bool isShiftTab = false;

  protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {

        if (keyData == Keys.Tab)
        {
            isTab = true;
            ShiftTab.Append("Tab");
        }
        else
        {
            isTab = false;
        }

        return base.ProcessCmdKey(ref msg, keyData);
    }



回答2:


You will need to have the MultiLine property set to true, and AcceptsTab also set to true.




回答3:


Or use e.KeyCode instead or e.KeyData, it worked for me

if (e.KeyCode == Keys.Tab | e.KeyData == Keys.Enter)


来源:https://stackoverflow.com/questions/22822697/tab-will-not-fire-keydown-or-keypress-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!