
24
LESSON 2 Creating Controls
WHAT’S IN A NAME, PART 3
Most C# developers add a control’s type as a suffix to its name as in
firstNameTextBox or resultLabel, but it’s becoming more common for devel-
opers to use a more generic word such as
Value or Field. The idea is that if you
decide to change the type of control that handles the value, you won’t need to
change the code that refers to the control.
For example, suppose your program uses a
TrackBar to let the user specify the
number of UFO detectors to purchase. If you name this control
numUfoDetectors-
Value
, they you won’t need to change the code if you later decide to let the user
select the value from a
NumericUpDown control instead of a TrackBar.
Some developers even omit the suffix completely as in
numUfoDetectors, although
that can be confusing if you need more than one control to represent a similar con-
cept or you want a variable inside the code that holds the numeric value represented
by the control.
For now, I recommend that you stick with the control’s full type name as a suffix.
Popular Properties
You’ll learn about key control properties as you go along and you can see a summary of key properties
for specific controls in Appendix B, but for now Table 2-1 summarizes some of the most useful proper-
ties. Note that not all controls have every property. For example, a
Button cannot display a border so
it has no
BorderStyle prop ...