Using Classes

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 Class

An 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

Property

Description

CompanyName

The company name associated with the application

CurrentCulture

The culture information for the current thread

CurrentInputLanguage

The input language for the current thread

ExecutablePath

The path to the EXE file that started the application

ProductName

The product name for current application

ProductVersion

The product version for current application

Table 1.2. Examples of Static Methods of the Application Class

Method

Description

DoEvents

Processes Windows messages currently in the queue

Exit

Closes and exits the application

ExitThread

Exits the message loop on the current thread and closes all windows on the current thread

Run

Begins a standard application message loop on the current thread

Using the Form Class

Whenever 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

Property

Description

BackColor

The background color of the form

BackgroundImage

The background image for the form

ClientSize

The size of the client area of the form

ControlBox

Indicates whether a control box needs to be displayed in the caption bar of the form

DesktopLocation

The location of the form on the Windows desktop

Enabled

Indicates whether a control can respond to user interaction

FormBorderStyle

The border style of the form

Handle

Gets the window handle ( hWnd ) of the form

HelpButton

Indicates whether a Help button is to be displayed on the caption bar of the form

Icon

Specifies the icon for the form

MaximizeBox

Indicates whether a maximize button is to be displayed on the caption bar of the form

MaximumSize

The maximum size to which this form can be resized

MinimizeBox

Indicates whether a minimize button is to be displayed in the caption bar of the form

MinimumSize

The minimum size to which this form can be resized

Modal

Indicates whether the form will be displayed modally (without allowing another form in the application to be active)

Name

The name of the form

Opacity

The opacity level of the form, measured as a decimal percentage from 0 (transparent) to 1 (fully opaque )

ShowInTaskbar

Indicates whether this form is displayed in the Windows taskbar

Size

The size of the form, expressed as a pair of pixel values (width and height)

StartPosition

Starting position of the form at runtime

TopMost

Indicates whether this form is displayed as the top-most form of the application

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 Properties

You 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.

graphics/note_icon.gif

You can choose whether to supply a Get procedure, a Set procedure, or both when you create a property. Without a defined Get procedure, the property becomes write-only, whereas a property lacking a Set definition is read-only.


Visual Inheritance

By 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.

graphics/01fig04.jpg

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.



Developing and Implementing WindowsR-based Applications with Visual BasicR. NET and Visual StudioR. NET Exam CramT 2 (Exam 70-306)
Developing and Implementing WindowsR-based Applications with Visual BasicR. NET and Visual StudioR. NET Exam CramT 2 (Exam 70-306)
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 188

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