Search code examples
c#winformskeypresskeydown

How to open new form when Enter as Tab?


When I Press Enter button, it acts as Tab with this code at form1_keydown event

 Control nextControl; 
 if (e.KeyCode == Keys.Enter)
 {
 nextControl = GetNextControl(ActiveControl, !e.Shift);
 nextControl.Focus();
 e.SuppressKeyPress = true;
 }

There is comboBoxin a form to which we press Enter button then open New Form.
How to do it because it doesn't work on cmb_KeyPressevent


Solution

  • Here You can wirte as:

     Control nextControl; 
     if (e.KeyCode == Keys.Enter)
     {
    nextControl = GetNextControl(ActiveControl, !e.Shift);
    nextControl.Focus();
    if(nextControl=Combo)
    {
    KeyPreview=false;   
    }
    e.SuppressKeyPress = true;
    }