VB.NET 1.1 Tutorial - GDI+ - Rectangle and RectangleF


Rectangle

A Rectangle structure stores a set of four integers that represent the location and size of a rectangle. A rectangle is defined by its width, height, and upper-left corner. By default, GDI+ will interpret the values entered as the amount of pixels on the screen.

There a two methods of creating a new Rectangle object.

Public Sub New( _
  ByVal location As Point, _
  ByVal size As Size _
)

This method initializes a new instance of the Rectangle class with the specified location and size.

  • location - A Point that represents the upper-left corner of the rectangular region.
  • size - A Size that represents the width and height of the rectangular region.

Public Sub New( _
  ByVal x As Integer, _
  ByVal y As Integer, _
  ByVal width As Integer, _
  ByVal height As Integer _
)

This method initializes a new instance of the Rectangle class with the specified location and size.

  • x - The x-coordinate of the upper-left corner of the rectangle.
  • y - The y-coordinate of the upper-left corner of the rectangle.
  • width - The width of the rectangle.
  • height - The height of the rectangle.

RectangleF

A RectangleF structure is only different to a Rectangle structure in the fact that floating point values are used instead of integers.

The two methods of creating a new RectangleF object are defined as:

Public Sub New( _
  ByVal location As PointF, _
  ByVal size As SizeF _
)

and

Public Sub New( _
  ByVal x As Single, _
  ByVal y As Single, _
  ByVal width As Single, _
  ByVal height As Single _
)

References

For more information on the Rectangle structure, visit MSDN at microsoft here.

For more information on the RectangleF structure, visit MSDN at microsoft here.

What Next?

Return to the Tutorial Contents.