Alternative to set focus from within the Enter event

前端 未结 3 1118
栀梦
栀梦 2021-01-22 18:27

I have a textbox and in some cases in Enter event I need to set the focus to a different textbox.

I tried that code:

 private void TextBox1_Enter(object          


        
3条回答
  •  长发绾君心
    2021-01-22 19:10

    You could handle the KeyPress event instead:

    private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
       if (e.KeyChar == (char)Keys.Return)
       {
          e.Handled = true;
          TextBox2.Focus();
       }
    }
    

提交回复
热议问题