Adding Features to a Windows Forms Application (2 of 5)

From webpage

Adding Features to a Windows Forms Application - How to add navigation features

 
(Page 2 of 5 )

Windows forms have features that make it easier for users to move around in the forms without using the mouse. These navigation features are described in figure 2-7.

The tab order is the order in which the controls on a form receive the focuswhen the user presses the Tab key. The tab order should usually be set so the focus moves left-to-right and top-to-bottom, beginning at the top left of the form and ending at the bottom right. However, in some cases you'll want to deviate from that order. For example, if you have controls arranged in columns, you may want the tab order to move down each column.

The tab order is initially set based on the order in which you add controls to the form. So if you add the controls in the right order, you won't need to alter the tab order. But if you do need to change the tab order, you can do so by adjusting the TabIndex property settings. The TabIndex property is simply a number that represents the control's position in the tab order, beginning with zero. So, the first control in the tab order has a TabIndex of 0, the second control's TabIndex is 1, and so on.

Incidentally, chapter 10 will show you another way to set the tab order of the controls for a form. You can do that by using Tab Order view. When a form consists of more than a few controls, it is easier to use this view than to set the tab order for one control at a time.

Access keys are shortcut keys that let the user move directly to a control. You set a control's access key by using the Text property. Just precede the letter in the Text property value that you want to use as the access key with an ampersand (&). Then, the user can activate the control by pressing Alt plus the access key.

If you assign an access key to a control that can't receive the focus, such as a label control, pressing the access key causes the focus to move to the next control in the tab order. As a result, you can use an access key with a label control to create a shortcut for a text box control, which can't have an access key.

Finally, you usually should set the AcceptButton and CancelButton properties for a form. These properties specify the buttons that are activated when the user presses the Enter and Esc keys. That can make it easier for a user to work with a form. If, for example, the AcceptButton property of the Invoice Total form in figure 2-3 is set to the Calculate button, the user can press the Enter key after entering a subtotal instead of using the mouse to click the Calculate button.

How to adjust the tab order

  1. Tab order refers to the sequence in which the controls receive the focus when the user presses the Tab key. You should adjust the tab order so the Tab key moves the focus from one control to the next in a logical sequence. 
  2. Each control has a TabIndex property that indicates the control's position in the tab order. You can change this property to change a control's tab order position. 
     
  3. If you don't want a control to receive the focus when the user presses the Tab key, change that control's TabStop property to False. 
     
  4. Label controls don't have a TabStop property so they can't receive the focus.

How to set access keys

  1. Access keys are shortcut keys that the user can use in combination with the Alt key to quickly move to individual controls on the form. 
  2. You use the Text property to set the access key for a control by placing an ampersand immediately before the letter you want to use for the access key. For example, &Invoice sets the access key to I, but I&nvoice sets the access key to n
     
  3. Since the access keys aren't case sensitive, &N and &n set the same access key. 
     
  4. When you set access keys, make sure to use a unique letter for each control. If you don't, the user may have to press the access key two or more times to select a control. 
     
  5. You can't set the access key for a text box. However, if you set an access key for a label that immediately precedes the text box in the tab order, the access key will take the user to the text box.

How to set the Enter and Esc keys

  1. The AcceptButton property of the form sets the button that will be activated if the user presses the Enter key.
  2. The CancelButton property of the form sets the button that will be activated if the user presses the Esc key. This property should usually be set to the Exit button. 
     
  3. You set the AcceptButton or CancelButton values by choosing the button from a drop-down list that shows all of the buttons on the form. So be sure to create and name the buttons you want to use before you attempt to set these values.

Another way to set the tab order

  • In chapter 10, you'll learn how to use Tab Order view to set the tab order of the controls on the form. If the form consists of more than a few controls, that is the best way to set that order.

Figure 2-7.  How to add navigation features

No comments: