I'm trying to create some classes for a small windows game in C#. I have a class Weapon with a constructor, which inherits from my base class Item:
public class Weapon : Item
{
public int Attack { get; set; }
//constructor
public Weapon(int id, string name, int value, int lvl, int attack) :
base(id, name, value, lvl)
{
Attack = attack;
}
}
Item class:
public class Item
{
public int ID { get; set; }
public string Name { get; set; }
public int Value { get; set; }
public int Lvl { get; set; }
//constructor
public Item(int id, string name, int value, int lvl)
{
ID = id;
Name = name;
Value = value;
Lvl = lvl;
}
}
This all works fine, I can call my constructor and create instances of Weapon object. However, I also want my Item and Weapon classes to inherit from the PictureBox class, like this:
public class Item : PictureBox
{
public int ID { get; set; }
public string Name { get; set; }
public int Value { get; set; }
public int Lvl { get; set; }
//constructor
public Item(int id, string name, int value, int lvl)
{
ID = id;
Name = name;
Value = value;
Lvl = lvl;
}
}
However applying the code above leads to an error "Constructor on type 'MyNamespace.Item' not found"
Am I approaching this the correct way? How can I get my Item base class to inherit from another base class?
EDIT: the error comes from within VS when opening the class file:
Why is it trying to open my class file in the form designer? I don't understand!