Home

Applications Accessories: The Size

     

Introduction

The distance from the left border to the right border of an object is referred to as its width. In the same way, the distance from the top to the bottom borders of a control is its height. This can be illustrated as follows:

The location and dimension of a control

The combination of the width and the height of an object is referred to as its size.

To support the size of an object, the System.Drawing namespace defines the Size structure. There are four characteristics that define a Size value: its location and its dimensions. A Size value must have a starting point (X, Y) just as the Point object was illustrated earlier. The width is the distance from the left to the right borders of a Size object. The height represents the distance from the top to the bottom borders of a Size value:

Size Representation

The members of a Size structure use values of type int. If you want to use decimal values, the .NET Framework provides the SizeF structure whose members deal with float values.

Characteristics of a Size

The Size and the SizeF structures are equipped with properties Width and Height that represent their width and height respectively.

To assist you with sizes, the Size structure provides the following constructor:

public Size(int width, int height);

The equivalent SizeF constructor uses the following syntax:

public SizeF(float width, float height);

You can also define a Size (or SizeF) object using a Point (or PointF) value. To support this, the Size structure is equipped with the following constructor:

public Size(Point pt);

The equivalent SizeF constructor uses the following syntax:

public SizeF(PointF pt);

After declaring a variable with this constructor, you can access its Width and Height properties to complete the definition of the Size object. If you already have the size of an object, you may only want to specify the dimensions of the variable.

 
 

Home Copyright © 2010-2014, FunctionX