I have some abstract classes in my program and the mother class inherits from PictureBox. My goal is that when I create an instance of my mother class, this instance should appear as a PictureBox in my form.
I tried to define the properties that would be needed for the PictureBox in the constructor of my Animal class.
Then as a second step I tried to define the picture that should appear in the form in the constructor of my African_bullfrog class. As a last step I tried to display the instance which is a PictureBox after the instantiation.
My problem is that my picture box is not displayed.
This is the code which is relevant for understanding the problem:
This is my mother class
Here I try to define the property of the PictureBox.
public abstract class Animal : PictureBox
{
public string name { get; }
public int age { get; }
public bool gender { get; }
public Image img { get; set; }
protected Animal(string name, int age, bool gender)
{
this.name = name;
this.age = age;
this.gender = gender;
this.Name = this.name;
this.Size = new Size(16, 16);
this.Location = new Point(100, 100);
}
This is my Amphibian class
public abstract class Amphibian : Animal, ISwim, IWalk
{
protected Amphibian(string name, int age, bool gender) : base(name, age, gender)
{
}
public void swim()
{
Debug.WriteLine("I swam!");
}
public void walk()
{
Debug.WriteLine("I walked!");
}
}
This is my Frog class
public abstract class Frog : Amphibian
{
protected Frog(string name, int age, bool gender) : base(name, age, gender)
{
}
}
This is the class from which an instance should be created
Here I try to define the picture of the PictureBox.
public sealed class African_bullfrog : Frog
{
public African_bullfrog(string name, int age, bool gender) : base(name, age, gender)
{
this.img = Zoo.Properties.Resources._01__African_Bullfrog;
this.Image = img;
}
}
this is my StartFrom class
Here I try to display the picture box
public partial class StartForm : Form
{
List<Type> animals = new List<Type>();
int amount_of_animals = 0;
public StartForm()
{
InitializeComponent();
fillAnimals();
}
private void btnCreateAnimal_Click(object sender, EventArgs e)
{
string selected = comboBoxAnimal.SelectedItem.ToString();
Debug.WriteLine(selected);
CreateAnimalForm createAnimalForm = new CreateAnimalForm(selected);
if (createAnimalForm.ShowDialog(this) == DialogResult.OK)
{
Animal animalInstance = new AnimalFactory().CreateInstance(createAnimalForm.animal, createAnimalForm.name, createAnimalForm.age, createAnimalForm.gender);
animalCounter();
animalInstance.Show();
}
}