我一直在尝试将代码移到单独的类中并更改了以下内容:
public partial class Questionnaire : Form
{
public Questionnaire()
{
InitializeComponent();
}
到
private readonly GetComponentSQL _getComponentSQL;
public Questionnaire(GetComponentSQL argGetComponentSQL)
{
_getComponentSQL = argGetComponentSQL;
InitializeComponent();
}
Form1包含button1,打开调查问卷。
private void button1_Click(object sender, EventArgs e)
{
Questionnaire q1 = new Questionnaire();
q1.ShowDialog(); // Shows GPU_Suggestion
}
关于调查问卷q1 = newQuestionnaire();
以下错误消息显示 - 没有给出对应于所需形式参数的参数' argGetComponentSQL' of Questionnaire.Questionnaire(GetComponentSQL)'
我已将button1_Click更改为:
private void button1_Click(object sender, EventArgs e)
{
Questionnaire q1 = new Questionnaire(GetComponentSQL argGetComponentSQL);
q1.ShowDialog(); // Shows GPU_Suggestion
}
但随后收到以下3条错误消息:
语法错误,','预期
' GetComponentSQL'是一种类型,在给定的上下文中无效
名称' argGetComponentSQL'在当前上下文中不存在
答案 0 :(得分:0)
Form2 questionnaire = new Form2();
questionnaire.Show();
this.Hide();
答案 1 :(得分:0)
在第
行Questionnaire q1 = new Questionnaire(GetComponentSQL argGetComponentSQL);
您正在尝试声明一个名为argGetComponentSQL的GetComponentSQL类型的新变量。这不会在将参数传递给构造函数(或任何其他方法或函数)的上下文中工作。相反,您必须在新调查表的实例化之前的行上声明变量,然后在将其作为参数传递给构造函数之前初始化它。