» Home
» Tutorials
» Search  
» Contact us 

Home » Tutorials » Introduction to Visual Basic .NET » Chapter 6

Chapter 6: Building Windows Applications
6.3: Creating More Complex Applications
6.3.7: Understanding Focus

Understanding Focus

There’s a problem with your Text Editor project. When you select another window and then switch back to the Text Editor window, the entire text in the box is highlighted. This happens because the focus has been set to the TextBox control. The control that has focus is the control that is currently selected, as shown in below figure. For example, if you have two buttons on a form, the code in the Click event handler for the button that has focus will be executed if you press Return.

If there are several text boxes on a form, any text you type will be entered into the text box that currently has the focus.

You can move focus between controls at run time by pressing the Tab key. For example, if the user of the form shown in below figure pressed the Tab key, focus would jump to the “I do not” button. If the user pressed the Tab key again, focus would jump back to the “I have focus” button.

 

The order in which the focus moves between the controls on a form is not arbitrary. As you place controls on a form, they are assigned a value for their TabIndex property. The first control to be placed on the form has a TabIndex of 0, the second 1, the third 2, and so on. This is the same order in which the controls will have the focus as you tab through them. If you have placed all your controls on the form and are not happy with the resulting tab order, you can manually change it yourself by using the Properties window to set the TabIndex properties of the controls.

 


Note that, although labels have a TabIndex property, it is not possible to tab to them at run time. Instead, the focus moves to the next control that can receive it, such as a text box or button.


 

Visual Basic .NET has a very handy feature for displaying the tab order of your controls. Select View* Tab Order, and your form will look something like this:

The tab order shown in the figure represents the order in which you placed your controls on the form. To remove the numbers, just select View* Tab Order once more.

 

click next Page - Using Multiple Forms.

Home | Link to Us | Partner Links | About us | Contact us

Copyright © 2009-2012 F1tutorials.com | All Rights Reserved