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

From webpage

Adding Features to a Windows Forms Application - The property settings for the Invoice Total form

 
(Page 3 of 5 )

Figure 2-8 shows the property settings for the Invoice Total form. As you can see, you don't need to change many properties to finish the design of this form. You only need to set four properties for the form, and you only use six of the properties (Name, Text, TextAlign, ReadOnly, TabStop, and TabIndex) for the controls. Depending on the order in which you create the controls, though, you may not need to change the TabIndex settings.

Notice that the three text boxes that display the form's calculation have their ReadOnly property set to True. This setting gives the text boxes a shaded appearance, as you saw in figure 2-3, and it prevents the user from entering text into these controls. In addition, the TabStop property for these text boxes has been set to False so the user can't use the Tab key to move the focus onto these controls.

Finally, the settings for the TabIndex properties of the text box and the two buttons are 1, 2, and 3. Since the label controls can't receive the focus, and since the TabStop property for the three read-only text boxes has been set to False, the user can press the Tab key to move the focus from the Subtotal text box to the Calculate button to the Exit button.

In addition, the Subtotal label has a TabIndex property of 0 and a Text property that includes an access key of S. As a result, the user can press Alt+S to move the focus to the control that has the next available tab index. In this case, that control is the Subtotal text box, which has a TabIndex property of 1.

Of course, this is just one way that the TabIndex properties could be set. If, for example, the TabIndex properties for the 10 controls were set from 0 through 9, from top to bottom in this summary, the tab order would work the same.

How to use Document Outline view

Document Outline view is a feature that became available with Visual Studio2005. To open the window for this view, you use the View->Other Windows->Document Outline command. This opens a window to the left of the Form Designer that lists the names of all of the controls that have been added to the current form.

This view makes it easy to check whether you've named all of the controls that you're going to refer to in your Visual Basic code. You can also select a control in the Form Designer by clicking on the name of the control in Document Outline view. Although these are minor benefits, it's worth experimenting with this view to see whether you're going to want to use it.

The property settings for the form  

 

 

Form1

Text

Invoice Total

 

AcceptButton

btnCalculate

 

CancelButton

btnExit

 

StartPosition

CenterScreen

 

 

The property settings for the controls

 

 

Default nameProperty Setting
Label1Text &Subtotal:
TextAlign TabIndex MiddleLeft 0
Label2Text TextAlign Discount percent: MiddleLeft
Label3Text Discount amount:
  TextAlignMiddleLeft
Label4 TextTotal:
  TextAlignMiddleLeft
TextBox1 NametxtSubtotal
  TabIndex1
TextBox2 NametxtDiscountPercent
  ReadOnly TabStopTrue False
TextBox3 NametxtDiscountAmount
  ReadOnly TabStopTrue False
TextBox4 NametxtTotal
  ReadOnly TabStopTrue False
Button1 NamebtnCalculate
  Text&Calculate
  TabIndex2
Button2 NamebtnExit
  TextE&xit
  TabIndex3

 

 

Note

  • To provide an access key for the Subtotal text box, you can set the TabIndex and Text properties for the Subtotal label as shown above. 

Figure 2-8.  The property settings for the Invoice Total form

No comments: