Control.SelectNextControl(Control, Boolean, Boolean, Boolean, Boolean) 方法


激活下一个控件。Activates the next control.

 bool SelectNextControl(System::Windows::Forms::Control ^ ctl, bool forward, bool tabStopOnly, bool nested, bool wrap);
public bool SelectNextControl (System.Windows.Forms.Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap);
member this.SelectNextControl : System.Windows.Forms.Control * bool * bool * bool * bool -> bool
Public Function SelectNextControl (ctl As Control, forward As Boolean, tabStopOnly As Boolean, nested As Boolean, wrap As Boolean) As Boolean



从其上开始搜索的 ControlThe Control at which to start the search.


如果为 true 则在 Tab 键顺序中前移;如果为 false 则在 Tab 键顺序中后移。true to move forward in the tab order; false to move backward in the tab order.


true 表示忽略 TabStop 属性设置为 false 的控件;false 表示不忽略。true to ignore the controls with the TabStop property set to false; otherwise, false.


true 表示包括嵌套子控件(子控件的子级);false 表示不包括。true to include nested (children of child controls) child controls; otherwise, false.


true 表示在到达最后一个控件之后从 Tab 键顺序中第一个控件开始继续搜索;false 表示不继续搜索。true to continue searching from the first control in the tab order after the last control has been reached; otherwise, false.



如果控件已激活,则为 true;否则为 falsetrue if a control was activated; otherwise, false.


下面的代码 exampleshows 在 SelectNextControl 包含某些控件的窗体中使用的方法。The following code exampleshows the SelectNextControl method being used in a form that has some controls. 每次单击窗体时,将激活下一个控件。Each time that you click the form, the next control is activated. ActiveControl属性获取容器控件中当前处于活动状态的控件。The ActiveControl property gets the currently active control in the container control.

private void Form1_Click(object sender, EventArgs e)
    Control ctl;
    ctl = (Control)sender;
    ctl.SelectNextControl(ActiveControl, true, true, true, true);
Private Sub Form1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Click
    Dim ctl As Control
    ctl = CType(sender, Control)
    ctl.SelectNextControl(ActiveControl, True, True, True, True)
End Sub

下面的代码示例演示了 SelectNextControl 一个窗体中使用的方法,该窗体具有 Button 和一些其他控件。The following code example shows the SelectNextControl method being used in a form that has a Button and some other controls. 单击时,将在 Button 激活后的下一个控件 ButtonWhen you click the Button, the next control after the Button is activated. 请注意,必须获取控件的父级 ButtonNotice that you have to get the parent of the Button control. 由于不是 Button 一个容器,因此 SelectNextControl 直接在上调用将 Button 不会更改激活。Since Button is not a container, calling SelectNextControl directly on the Button would not change the activation.

private void button1_Click(object sender, EventArgs e)
    Control p;
    p = ((Button) sender).Parent;
    p.SelectNextControl(ActiveControl, true, true, true, true);
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
    Dim p As Control
    p = CType(sender, Button).Parent
    p.SelectNextControl(ActiveControl, True, True, True, True)
End Sub


SelectNextControl方法按 tab 键顺序激活下一个控件。如果控件的 Selectable 样式位设置为 true in ControlStyles ,则它包含在另一个控件中,并且其所有父控件都可见且已启用。The SelectNextControl method activates the next control in the tab order if the control's Selectable style bit is set to true in ControlStyles, it is contained in another control, and all its parent controls are both visible and enabled.

以下列表中的 Windows 窗体控件不可选择。The Windows Forms controls in the following list are not selectable. 从列表中的控件派生的控件也将无法选择。Controls derived from controls in the list will also not be selectable.

使用 "键盘 (" 选项卡、"SHIFT + TAB") ,并通过调用 SelectSelectNextControl 方法,或通过将 ContainerControl.ActiveControl 属性设置为当前窗体来更改焦点时,焦点事件将按以下顺序发生:When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl.ActiveControl property to the current form, focus events occur in the following order:

  1. Enter

  2. GotFocus

  3. Leave

  4. Validating

  5. Validated

  6. LostFocus

如果将 CausesValidation 属性设置为 false ,则将 Validating Validated 取消和事件。If the CausesValidation property is set to false, the Validating and Validated events are suppressed.