1

i mean graphic2D contains, the function to check if mouse e.X and e.Y is clicked inside that graphic. since it is available on java, i would like to know if there's something simillar on c#

Robert Tirta
  • 2,593
  • 3
  • 18
  • 37

1 Answers1

3

You can do something like this in C#

List<ShapeObj> ShapeObj_list; //The list of objects drawn.

private void OnMouseDown(object sender, MouseEventArgs e)
{
    foreach(ShapeObj obj in ShapeObj_list)
    {
        if(obj.InsideTheObject(e.X, e.Y))
        {
            //Do Something
        }
    }
}

In the class ShapeObj implements the function InsideTheObject:

public class ShapeObj
{

    public Point Location { get; set; }
    public Size Size {get; set; }

    public bool InsideTheObject(int x, int y)
    {
        Rectangle rc = new Rectangle(this.Location, this.Size);
        return rc.Contains(x, y);
    }
}
Mohit S
  • 13,723
  • 6
  • 34
  • 69