Control.SelectNextControl(Control, Boolean, Boolean, Boolean, Boolean) Control.SelectNextControl(Control, Boolean, Boolean, Boolean, Boolean) Control.SelectNextControl(Control, Boolean, Boolean, Boolean, Boolean) Control.SelectNextControl(Control, Boolean, Boolean, Boolean, Boolean) Method

定义

激活下一个控件。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 Control Control Control

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

forward
Boolean Boolean Boolean Boolean

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

tabStopOnly
Boolean Boolean Boolean Boolean

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

nested
Boolean Boolean Boolean Boolean

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

wrap
Boolean Boolean Boolean 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

下面的代码示例演示SelectNextControl了一个Button窗体中使用的方法,该窗体具有和一些其他控件。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不是一个容器,因此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

注解

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

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

适用于

另请参阅