private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                if (this.ActiveControl != null)
                {
                    bool b = this.SelectNextControl(this.ActiveControl, true, true, true, false);
                }
            }

        }
 
MSDN:

Control.SelectNextControl 方法:激活下一个控件。

public bool SelectNextControl(
	Control ctl,
	bool forward,
	bool tabStopOnly,
	bool nested,
	bool wrap
)

参数

ctl
类型:System.Windows.Forms.Control
Control
forward
类型:System.Boolean
false 则在 Tab 键顺序中后移。
tabStopOnly
类型:System.Boolean
false 表示不忽略。
nested
类型:System.Boolean
false 表示不包括。
wrap
类型:System.Boolean
false 表示不继续搜索。

返回值

类型:System.Boolean
false

SelectNextControl 方法将激活 Tab 键顺序中的下一个控件。

从该列表中的控件派生的控件也是不可选择的。

ContainerControl.ActiveControl 属性设置为当前窗体等方式更改焦点时,焦点事件按以下顺序发生:

  1. Enter

  2. GotFocus

  3. Leave

  4. Validating

  5. Validated

  6. LostFocus

Validated 事件。

 

相关文章:

  • 2022-12-23
  • 2021-10-25
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2021-07-13
  • 2022-12-23
猜你喜欢
  • 2021-10-04
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
相关资源
相似解决方案