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

定义

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

public:
 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

参数

ctl
Control

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

forward
Boolean

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

tabStopOnly
Boolean

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

nested
Boolean

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

wrap
Boolean

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

下面的代码示例演示了在具有 Button 和其他一些控件的窗体中使用的 SelectNextControl 方法。The following code example shows the SelectNextControl method being used in a form that has a Button and some other controls. 当你单击 Button 时,将激活 Button 之后的下一个控件。When you click the Button, the next control after the Button is activated. 请注意,必须获取 Button 控件的父级。Notice that you have to get the parent of the Button control. 由于 Button 不是一个容器,因此直接对 Button 调用 SelectNextControl 将不会更改激活。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

注解

如果将控件的 Selectable 样式位设置为 ControlStyles中的 true,则 SelectNextControl 方法将激活 tab 键顺序中的下一个控件,该控件包含在另一个控件中,并且其所有父控件都可见且已启用。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.

使用键盘(TAB、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,则将取消 ValidatingValidated 事件。If the CausesValidation property is set to false, the Validating and Validated events are suppressed.

适用于

另请参阅