I'm trying to make a minipaint application which has three buttons(rectangle, circle and line). I'm having problem with selecting and moving shapes with mouse. For example I have this rectangle class which inherits color, thickness from shape:
class rectangle : shape
{
public int length { get; set; }
public int width { get; set; }
public override void Draw(Graphics g)
{
g.DrawRectangle(new Pen(color), new Rectangle(startx, starty, width,length));
}
}
Now, I want my panel1_MouseDown to select a rectangle in my panel whenever I click on any part of rectangle. All drawn shapes are added to a list named lstShapsOnForm and drawable is an abstract class that has abstract method of draw and property x y.
abstract class Drawable
{
public int x { get; set; }
public int y { get; set; }
public abstract void draw(Graphics g);
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
foreach (Drawable o in lstShapsOnForm)
{
if (e.Location.X >= o.x || e.Location.X < o.x)
propertyGrid1.SelectedObject = o;
}
}
How should I make this work?