Chapter 20: Logic Statements, Enabling and Disabling Controls, and Focus

 

Overview

The concept of ready-made controls for Windows-class computer programs first appeared in the mid-1980s and blossomed in the 1990s when the controls were standardized by Microsoft. This is about the time that Charles Petzold appeared on the scene. He wrote books that were many hundreds of pages long, explaining all the idiosyncrasies of each type of standard control. His books were necessary to explain to the programming public how to use these wonderful new devices. He does the same thing today, and more.

Once the controls became standardized there was little room for wildcatting in the controls business ” programmers did everything the Microsoft way. But programmers were relieved of the responsibility of picking and choosing all the details in the presentation and actuation of common controls, and that was worth a lot.

In the early 1990s the first integrated development environment (IDE) suites began to appear. Today you can install the necessary controls in a major Windows program in one afternoon; in the past it took many days. This increase in programmer productivity is assisted by Microsoft s willingness to package all the code snippets necessary to tie a control to the other source code and insert them into the source code at the appropriate places. In effect, the painful lessons taught by Charles Petzold in his computer texts were all mechanized and included in the compiler. No wonder the average compiler grew from about 100 K in size to a 1000 K in 20 years !

With version 2.0 of the Visual Studio C# compiler you will also find more automation. When the compiler finds an error in your code, it will tell you how to fix it. For example, in the old days, if you neglected to include a file at the top of the source code that contained the machine code to support a computer statement such as printf(), the error that was written across the bottom of the IDE would simply imply that some form of documentation was missing. It was left to the programmer to figure out what that documentation was. Today s compiler is much more specific. If you use the pen descriptor DashStyle in your code and forget to include the using file using System.Drawing.Drawing2D, the compiler will tell you to place that using statement at the top of your source code to fix the problem.

To the casual observer there remain too many choices among controls ” why are there so many ways to ask a user a simple question? The answer is because no compiler manufacturer wants to eliminate any single element of the controls suite, as one never knows if that particular control will come in handy next year. These standard controls will be with us in perpetuity.

Every control is sequenced the same way:

  1. The control presents all options to the user. In some cases the user only gets to pick one option; in others, multiple choices may be made.

  2. The control collects the user response(s) whenever the user indicates that he has made the final choice or choices. Event handlers are placed to shift the program s focus to a particular group of fol-low-on code as soon as the user has done his job.

  3. The event handler takes over and accomplishes whatever task is desired. When the event handler is finished, the focus may be sent back to the original control (for example, when text checking occurs in a text box), or it may be sent back to the window where the control is located (so the user may decide what to do next). Before a control is exited, the user s choice(s) must be placed in persistent data locations since those choices disappear as soon as the exit action on the control occurs.

Automation of #1 and #2 above came easily to the integrated development environment, but #3 continues to be the responsibility of the individual programmer.

These are the common controls that will be demonstrated in this chapter:

  • Edit controls

  • Radio buttons

  • Check boxes

  • List boxes

  • Combo boxes (edit box with scrollable text)

  • Group boxes, panels, and radio groups

  • Tab controls

The tab controls are the latest addition to the controls and they serve a useful purpose in most modern programs.

 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net