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 會在定位順序中向前移動。false 會在定位順序中向後移動。true to move forward in the tab order; false to move backward in the tab order.


true 會忽略 TabStop 屬性設定為 false 的控制項,否則為 falsetrue to ignore the controls with the TabStop property set to false; otherwise, false.


true 會包含巢狀 (子控制項的子系) 子控制項,否則為 falsetrue to include nested (children of child controls) child controls; otherwise, false.


true 會在到達最後一個控制項後,從定位順序中的第一個控制項繼續搜尋,否則為 falsetrue 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 不是容器,所以直接在 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 方法會啟動定位順序中的下一個控制項,它會包含在另一個控制項中,而且其所有父控制項都是可見和啟用的。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 Forms 控制項無法選取。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.