Give Your Forms a Base Create a base form class to ensure that all of the forms in your application behave consistently. This technique minimizes the amount of repetitive code you need to write to manage the user's interaction with your forms. Great Windows applications have a consistent user interface. As the user learns how to work with one form in the application, the user can leverage that knowledge as they work with other forms in the application. This minimizes the requirements for end-user training and support and maximizes end-user satisfaction. | " | Add event handlers to the base form class to handle form and control events consistently on any form that inherits from the base form class.
| " |
You can achieve a consistent feel throughout your user interface by building your own base form class. In this base form class you can write the code for all of the standard user interaction features. Every form in the application that inherits from your base form class will automatically support any feature defined in the base form class. Creating the Base Form Class You create a base form class the same way you create any form in a Windows application; just add a new form to a Windows Application project. Giving the base form class a clear name, such as eOrderOnLineWinBase, will help you keep track of the base form class. You may, or may not, want to add controls to this base form class. If there are common UI elements on many of the forms of your application, such as a particular icon or set of buttons, then it is useful to add these to the base form class. Common UI elements in the base form class then appear on every form that inherits from the base form class, a technique referred to as visual inheritance. Frequently, however, you may find that your forms don't have common UI elements, so it is not desirable to add common controls in fixed positions to your base form class. You should add event handlers to the base form class to handle form and control events consistently on any form that inherits from the base form class. By leveraging the code in the base form, you minimize the amount of repetitive code in the forms. For example, to give the user a visual indicator of the control that has focus, you can change the background color of the active control on the form. To be consistent, every form should incorporate the same technique. You could add the code to handle the Enter and Leave events of every control to every form in your application; but this could require a significant amount of code since a Windows application of any significant size can require 50 or more forms. It makes more sense to write this code one time and then reuse it from every form in your application. | & | | 
By: Deborah Kurata
Deborah Kurata is cofounder of InStep Technologies Inc., a professional consulting firm that focuses on turning your business vision into reality using Microsoft .NET technologies. She has over 15 years of experience in architecting, designing and developing successful applications.
Deborah is the author of several books, including Best Kept Secrets in .NET (Apress), Doing Objects in Visual Basic 6.0 (SAMS) and Doing Web Development: Client-Side Techniques (Apress). She is on the INETA Speaker’s Bureau, is a well-known speaker at technical conferences, and is a Microsoft Most Valuable Professional (MVP). After a hard day of coding and taking care of her family, Deborah enjoys blowing stuff up (on her XBox of course).
Some of the information in this article was obtained from her upcoming book, Doing Objects in VB 2005.
deborahk@insteptech.com | Fast Facts | | A base form class makes it easy for you to give your users a consistent experience without needing to write a lot of user interface code. | |
|