未找到类型xxx上的构造函数


class ItemBaseModel : TextBox
{
public string item_name { get; set; }
public ItemBaseModel(string item_name)
{           
this.item_name = item_name;
this.ReadOnly = true;
this.Multiline = true;
this.TextAlign = HorizontalAlignment.Center;
}
}

这是我的基类,它派生自TextBox控件。

class ItemWeaponModel : ItemBaseModel
{
int min_dmg { get; set; }
int max_dmg { get; set; }
}
public ItemWeaponModel(string item_name, int min_dmg, int max_dmg) : base(item_name)
{
this.min_dmg = min_dmg;
this.max_dmg = max_dmg;
}

这是我的课,它源于第一节课。

现在,问题是,当我在解决方案资源管理器中打开ItemWeaponModel.cs文件时,我会收到以下错误:

构造函数错误

尽管我可以毫无问题地运行我的项目。发生了什么?感谢您的回复。

问题是设计器希望您的类具有无参数构造函数。它不能呼叫任何其他人。

试着为设计器提供一个简单的无参数构造函数。您不必在实际的应用程序代码中使用它。

class ItemBaseModel : TextBox
{
public string item_name { get; set; }
public ItemBaseModel(string item_name)
{           
this.item_name = item_name;
this.ReadOnly = true;
this.Multiline = true;
this.TextAlign = HorizontalAlignment.Center;
}
public ItemBaseModel() : this("default")
{}
}

最新更新