Visual C#

Applications Accessories: The Size

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…

1 min read207 words4 code samples

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:

A figure's size is a geometric attribute that defines its height and width. The .NET Framework includes the Size and SizeF structures to represent these dimensions.

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#

Use the constructor below to initialize a Size object:

C#
public Size(int width, int height);

The equivalent SizeF constructor uses the following syntax:

C#
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:

C#
public Size(Point pt);

The equivalent SizeF constructor uses the following syntax:

C#
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-2011 C# Key