Control.SelectNextControl(Control, Boolean, Boolean, Boolean, Boolean) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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);
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
Parameters
- forward
- Boolean
true
to move forward in the tab order; false
to move backward in the tab order.
- tabStopOnly
- Boolean
true
to ignore the controls with the TabStop property set to false
; otherwise, false
.
- nested
- Boolean
true
to include nested (children of child controls) child controls; otherwise, false
.
- wrap
- Boolean
true
to continue searching from the first control in the tab order after the last control has been reached; otherwise, false
.
Returns
true
if a control was activated; otherwise, false
.
Examples
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. 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
The following code example shows the SelectNextControl method being used in a form that has a Button and some other controls. When you click the Button, the next control after the Button is activated. Notice that you have to get the parent of the Button control. 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
Remarks
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.
The Windows Forms controls in the following list are not selectable. Controls derived from controls in the list will also not be selectable.
LinkLabel (when there is no link present in the control)
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:
If the CausesValidation property is set to false
, the Validating and Validated events are suppressed.