Work with Rectangle type : Rectangle « 2D Graphics « C# / C Sharp






Work with Rectangle type

 
using System;
using System.Drawing;



class Program {
    static void Main(string[] args) {
        Rectangle r1 = new Rectangle(0, 0, 100, 100);
        Point pt3 = new Point(101, 101);

        if (r1.Contains(pt3))
            Console.WriteLine("Point is within the rect!");
        else
            Console.WriteLine("Point is not within the rect!");

        // Now place point in rectangle's area.
        pt3.X = 50;
        pt3.Y = 30;

        if (r1.Contains(pt3))
            Console.WriteLine("Point is within the rect!");
        else
            Console.WriteLine("Point is not within the rect!");
    }
}

 








Related examples in the same category

1.Simplest code to draw a RectangleSimplest code to draw a Rectangle
2.Draw SquareDraw Square
3.Draw RectangleDraw Rectangle
4.Add size and pointAdd size and point