Hello everyone. I don't know how to call a method from abstract class in protected method. I know that to call method of some class I need to create an object, then object.Method. What are the other ways to call methods?

Here is the example code:

static public List<Figure> list = new List<Figure>();
public abstract class Figure
{
   public void ReDraw()
        {
            foreach (Figure row in list)
            {

                if (typeof(Circle) == row.GetType())
                {
                    Circle tmp = row as Circle;
                    tmp.Draw(pictureBox1, tmp.mypen, tmp.pos, tmp.num, tmp.size);
                }

                else if (typeof(RightFigure) == row.GetType())
                {
                    RightFigure tmp = row as RightFigure;
                    tmp.Draw(pictureBox1, tmp.mypen, tmp.pos, tmp.num);
                }

                else if (typeof(Triangle) == row.GetType())
                {
                    Triangle tmp = row as Triangle;
                    tmp.Draw(pictureBox1, tmp.mypen);
                }
            }
        }
}

protected override void OnKeyDown(KeyEventArgs e)
{
  if(button1)
  {// call here Method ReDraw(); How to call it?}
  else if(button2)
  {//call here Method ReDraw(); How to call it? }
}

Problem is that class is abstract.
Thank you for your help. :cool:

I don't know how to call a method from abstract class in protected method.

Unless the method is static you don't call it. That's the idea: abstract classes cannot be instantiated and must be inherited from to be used in any useful manner.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.