Article ID: 109261 - View products that this article applies to.
This article was previously published under Q109261
This article shows by example how to use the TAB keypress within a control, such as a text box. Normally, the TAB key causes the focus to move away from that control. The sample program in this article shows you how to change this behavior so you can use the TABs within a text box.
The sample program does this by setting the TabStop property of all controls on the form to False when the text box has the focus. Tabbing changes focus between any controls which have a TabStop property equal to True, which is the default. When the TabStop property is true for one or more controls on a form, Visual Basic does not allow tabs to be entered directly into a control.
Step-by-Step ExampleIn the example below, the Text2 box will accept and hold TAB keystrokes, keeping them in the Text property along with the other entered characters. The Text1 and Text3 boxes will not accept TAB keystrokes. When Text1 and Text3 have the focus, pressing the TAB key changes the focus to the next control in the tab order.
Tab OrderBy default, Visual Basic assigns tab order to controls in the order you draw them on a form. Each new control is placed last in the tab order. You can control the order that controls gain focus in your application by changing the tab order at design time through the Properties window, or at run time through code.
To change tab order at design time:
A control whose TabStop property has been set to False maintains its position in the actual tab order as set by the TabIndex property, even though the control is skipped when you cycle through the controls by using the TAB key. If the TabStop property is False for all controls on the form, you can enter TAB keystrokes into MultiLine text boxes.
Controls CollectionThe Controls collection is a collection whose elements represent each control on a form, including elements of control arrays. The Controls collection has a single property (Count) that specifies the number of elements in an array.
The Controls collection enumerates loaded controls on a form and is useful for iterating through them. The index in the syntax is between 0 and Controls.Count-1.
NOTE: Controls is a keyword but not a reserved word. It identifies an intrinsic form-level variable named Controls. If you omit the optional form reference, you must include the Controls keyword. If you include a form reference, you can omit the Controls keyword. For example, the following two lines have the same effect:
MyForm.Controls(6).Top = MyForm.Controls(5).Top + increment MyForm(6).Top = MyForm(5).Top + increment
Article ID: 109261 - Last Review: October 29, 2003 - Revision: 2.0
Contact us for more help
Connect with Answer Desk for expert help.