Region Constructor (Rectangle)

 

Initializes a new Region from the specified Rectangle structure.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public:
Region(
	Rectangle rect
)

Parameters

rect
Type: System.Drawing::Rectangle

A Rectangle structure that defines the interior of the new Region.

This method creates a new Region with a rectangular interior. The interior is defined by the rect parameter.

The following code example demonstrates how to use the Region constructor and MakeEmpty method. This example is designed to be used with Windows Forms. Create a form and paste the following code into it. Call the FillEmptyRegion method in the form's Paint event-handling method, passing e as PaintEventArgs.

private:
   void FillEmptyRegion( PaintEventArgs^ e )
   {
      // Create a region from a rectangle.
      Rectangle originalRectangle = Rectangle(40,40,40,50);
      System::Drawing::Region^ smallRegion = gcnew System::Drawing::Region( originalRectangle );

      // Call MakeEmpty.
      smallRegion->MakeEmpty();

      // Fill the region in red and draw the original rectangle
      // in black. Note there is nothing filled in.
      e->Graphics->FillRegion( Brushes::Red, smallRegion );
      e->Graphics->DrawRectangle( Pens::Black, originalRectangle );
   }

.NET Framework
Available since 1.1
Return to top
Show: