How can I make the rectangles clickable, C#

Axess picture Axess · Jun 29, 2012 · Viewed 7.2k times · Source

The code can generate rectangles (Rectangle rectangle) at runtime. The position of rectangles may change according to users' choices.

I want to add code in the method where it creates rectangles to make the rectangles clickable. And after user clicking the rectangle, there will be a new window to show content just like text.

Answer

Hyralex picture Hyralex · Jun 29, 2012

You can use Contains method of the Rectangle object.

private Rectangle _myRectangle;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
    if (this._myRectangle.Contains(e.Location))
    {

    }
}