Many classes are included in the Framework class library (FCL) that may be used within your application. These classes provide common functionality, such as drawing graphics onscreen, sending messages over the Internet, or creating random numbers . Using the Application ClassAn example of a class available within the FCL is the Application class, which provides properties that may be used by the code in order to obtain information about the current application (see Table 1.1), as well as methods that may be used, such as the ability to start and close an application (see Table 1.2). These tables provide some examples of the properties and methods of the Application class. Many more properties and methods are available; refer to the .NET Framework help file for the full list. Table 1.1. Examples of Static Properties of the Application Class
Table 1.2. Examples of Static Methods of the Application Class
Using the Form ClassWhenever you create an instance of the System.Windows.Forms.Form class, the instance has many useful public properties that may be configured programmatically or through the Solution Explorer, as described earlier in this chapter. Table 1.3 provides a list of many of the more useful public properties of the Form class. Table 1.3. Examples of Public Properties of the Form Class
Forms also include many public methods that may be used in order to act upon an instance of the Form classfor example, the Show() method, which will cause an instance of the class to be displayed, the Hide() method, which temporarily stops displaying the form without closing it, and the Close() method, which is used to terminate an instance of a form. Some of the methods will take into account other properties set on a form at the time of the invocation of the Me.Show() command in order to provide the final result, such as the specification of the Opacity property. If this property is set at a value between 0 (transparent) and 1 (opaque), then the resultant form will be partially transparent when the Show() method is called. In order to place a form on top of others already present, you would set the form's TopMost property to True before invoking the Show() method. Custom PropertiesYou may create custom properties for an object by writing code. For example, you could add a property named MyProperty to a form with this code: Private m_MyProperty As Integer Public Property MyProperty() As Integer Get MyProperty = m_MyProperty End Get Set(ByVal Value As Integer) m_MyProperty = Value End Set End Property Here, m_MyProperty is a variable that will store the value of the property. When you read the value of the property, the Get procedure is invoked to return the value of the variable. When you write a value to the property, the Set procedure places the value into the variable.
Visual InheritanceBy default, forms are instances of the Form class. But forms can also inherit from other forms, through a process known as Visual Inheritance . Visual Inheritance is simply a way of creating an inherited form within the Visual Studio .NET environment. Within the Solution Explorer, you may also specify inheritance by right-clicking the project name and selecting Add, Add Inherited Form from the shortcut menu. This will open the Inheritance Picker, shown in Figure 1.4. Figure 1.4. The Inheritance Picker showing several items that may be selected for inheritance.
Once you select an object to inherit from, the public and protected members of that class will be accessible to the form. For example, if you define a public property called MyProperty on a form named Form1 and then create Form2 via Visual Inheritance from Form1, Form2 will automatically have a MyProperty property. |