通过


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

定义

激活下一个控件。

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);
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 搜索的起始位置。

forward
Boolean

true 在 Tab 键顺序中向前移动; false 以 Tab 键顺序向后移动。

tabStopOnly
Boolean

true如果忽略属性设置为false的控件TabStop,则为 ;否则为 false

nested
Boolean

true 包含嵌套的(子控件的子级)子控件;否则,为 false.

wrap
Boolean

true 在到达最后一个控件后,继续从 Tab 键顺序中的第一个控件进行搜索;否则,为 false.

返回

true 如果控件已激活,则为否则,为 false.

示例

下面的代码示例演示 SelectNextControl 了在具有某些控件的窗体中使用的方法。 每次单击窗体时,都会激活下一个控件。 该 ActiveControl 属性获取容器控件中的当前活动控件。

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 控件的窗体中使用的方法。 单击该 Button控件时,激活后的 Button 下一个控件。 请注意,必须获取控件的父级 Button 。 由于Button不是容器,因此直接Button调用SelectNextControl不会更改激活。

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

注解

如果控件的样式位设置为 <a0/>,则该方法将激活 Tab 键顺序中的下一个控件,该控件包含在另一个控件中,并且其所有父控件均可见且已启用。

以下列表中的 Windows 窗体控件不可选择。 从列表中的控件派生的控件也不可选择。

使用键盘(TAB、SHIFT+TAB 等)更改焦点时,通过调用 SelectSelectNextControl 方法,或通过将 ContainerControl.ActiveControl 属性设置为当前窗体来更改焦点时,焦点事件按以下顺序发生:

  1. Enter

  2. GotFocus

  3. Leave

  4. Validating

  5. Validated

  6. LostFocus

CausesValidation如果该属性设置为false,则Validating取消该属性和Validated事件。

适用于

另请参阅