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.

有帮助吗?

解决方案

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);
    }

其他提示

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

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

if (e.KeyCode == Keys.Tab | e.KeyData == Keys.Enter)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top