Home

The Forms of an Application:
The Client Area of a Form

 

Introduction

When a form has been created, you can add Windows controls to it. These controls can be positioned only in a specific area, the body of the form. The body spans from the left border of the form, excluding the border itself, to the right border of the form, excluding the border. It also spans from the top side, just under the title bar, to the bottom border, excluding the bottom border, of the form. The area that the form makes available to the controls added to it is called the client area:

If a control is positioned on a form, its location uses a coordinate system whose origin is positioned on the top-left section of the client area (just under the title bar). The x axis moves from the origin to the left. The y axes moves from the origin down:

The origin of the coordinate system and its axes

The distance from the left border of the client area to the left border of the control is the Left property. The distance from the top border of the client area to the top border of the control is the Top property. These can be illustrated as follows:

To know the amount of space that a form is making available to its child control, you can access the form's ClientSize property.

The Background Color of a Form

The client area of a form is painted with a color specified by the operating system. To change the color to anything you like, you can use the BackColor field of the Properties window. If you click the arrow of its combo box, it displays a property sheet with three tabs that divide the color in categories:

To programmatically change its color, assign a color from the Color structure to the BackColor property. Here is an example:

public class Exercise : System.Windows.Forms.Form
{
    public Exercise()
    {
        InitializeComponent();
    }

    private void InitializeComponent()
    {
        Icon = new Icon(@"C:\Programs\RedBook.ico");
        Text = "Windows Fundmentals";

        BackColor = Color.BurlyWood;
    }
}

This would produce:

Back Color

If you look closely, you will notice that only the client area of the form is painted. The borders, since they are not part of the client area, are not painted.

 

Previous Copyright © 2007 FunctionX, Inc. Next