gpt4 book ai didi

c# - 继承窗体时找不到类型为 ""的构造函数

转载 作者:行者123 更新时间:2023-12-04 00:32:43 26 4
gpt4 key购买 nike

创建了一个继承自另一个表单的表单,但由于某种原因,我在未找到类型“baseForm”上收到错误构造函数。这是继承类构造函数:

public partial class loadHtmlFormsDatabaseForm :      NEA_Official.createHtmlFormsForm
{
List<field> listOfFields = new List<field>();
static string username1;
int originalListOfFieldsCount;
htmlFormsProject loadedProject;

public loadHtmlFormsDatabaseForm(htmlFormsProject loadProject, string username) : base(username1)
{
username1 = username;
loadedProject = loadProject;
InitializeComponent();
}

这是基类的构造函数:

    public partial class createHtmlFormsForm : Form
{
List<field> listOfFields = new List<field>();
string username = "";

public createHtmlFormsForm(string username1)
{
username = username1;
InitializeComponent();
}

最佳答案

你可以通过重载基类中没有参数的构造函数来修复它,如下所示:

public partial class createHtmlFormsForm : Form
{
List<field> listOfFields = new List<field>();
string username = "";

public createHtmlFormsForm(string username1)
{
username = username1;
InitializeComponent();
}
public createHtmlFormsForm()
{
InitializeComponent();
}
}

如果您不需要不带参数的构造函数,您可以将其创建为私有(private)的:

public partial class createHtmlFormsForm : Form
{
List<field> listOfFields = new List<field>();
string username = "";

public createHtmlFormsForm(string username1)
{
username = username1;
InitializeComponent();
}
// private contructor with no parameter
private createHtmlFormsForm()
{
InitializeComponent();
}
}

或者您可以使用过时的属性:

public partial class createHtmlFormsForm : Form
{
List<field> listOfFields = new List<field>();
string username = "";

public createHtmlFormsForm(string username1)
{
username = username1;
InitializeComponent();
}

[Obsolete("Designer only", true)]
public createHtmlFormsForm()
{
InitializeComponent();
}
}

关于c# - 继承窗体时找不到类型为 ""的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42469984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com