Rectangle Constructor (Int32, Int32, Int32, Int32)
.NET Framework (current version)
Initializes a new instance of the Rectangle class with the specified location and size.
Assembly: System.Drawing (in System.Drawing.dll)
Parameters
- x
-
Type:
System::Int32
The x-coordinate of the upper-left corner of the rectangle.
- y
-
Type:
System::Int32
The y-coordinate of the upper-left corner of the rectangle.
- width
-
Type:
System::Int32
The width of the rectangle.
- height
-
Type:
System::Int32
The height of the rectangle.
The following code example demonstrates the Rectangle, Intersect, IsEmpty, and IntersectsWith members. This example should be used with a Windows Form. Paste this code into a form and call this method when handling the form's Paint event, passing e as PaintEventArgs.
private: void InstanceRectangleIntersection( PaintEventArgs^ e ) { Rectangle rectangle1 = Rectangle(50,50,200,100); Rectangle rectangle2 = Rectangle(70,20,100,200); e->Graphics->DrawRectangle( Pens::Black, rectangle1 ); e->Graphics->DrawRectangle( Pens::Red, rectangle2 ); if ( rectangle1.IntersectsWith( rectangle2 ) ) { rectangle1.Intersect( rectangle2 ); if ( !rectangle1.IsEmpty ) { e->Graphics->FillRectangle( Brushes::Green, rectangle1 ); } } }
.NET Framework
Available since 1.1
Available since 1.1
Show: