Hi everyone. :?:
I have a big problem. I have different classes: Square, Circle, Star, Triangle. They allow me to draw figures on the picturebox. I have different buttons on my form. Example button "Circle" works like that:
Circle circle = new Circle();
list.Add(circle);
circle.Draw(this.pictureBox1, circle.mypen, circle.pos, circle.num);
When I create a new object I store it in list:
static public List<Object> list = new List<Object>();
And here is the problem:
When I do smth (move, spin) with figures I need to redraw them again. I have an example how to draw circles:
foreach (Object elem in list)
{
Circle gh1 = elem as Cirlce;
gh1.Draw(pictureBox1, gh1.mypen, gh1.pos, gh1.num);
}
And it draws circles on the picturebox. The problem is that my list has 4 types of figures. So, I need to get the type of the current object in list and call method for it. Because all figures have different methods of drawing. When I create
Object obj = elem as Object;
obj.Draw(pictureBox1,obj.mypen,obj.pos,obj.num);
Compiler say that there is no method Draw() for obj. I don't know how to make it possible to analyze type of object automatically and call appropriate method.
Can you help me please? How to realize it? I am newbie to C#.
Thank you for your help.