没有给出对应于require形式参数的参数(从表单中打开表单)

时间:2016-01-25 00:51:28

标签: c#

我一直在尝试将代码移到单独的类中并更改了以下内容:

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'在当前上下文中不存在

2 个答案:

答案 0 :(得分:0)

你正在做什么? 如果您想使用按钮打开表单,请执行以下操作:

Form2 questionnaire = new Form2();
questionnaire.Show();
this.Hide();

答案 1 :(得分:0)

在第

Questionnaire q1 = new Questionnaire(GetComponentSQL argGetComponentSQL);

您正在尝试声明一个名为argGetComponentSQL的GetComponentSQL类型的新变量。这不会在将参数传递给构造函数(或任何其他方法或函数)的上下文中工作。相反,您必须在新调查表的实例化之前的行上声明变量,然后在将其作为参数传递给构造函数之前初始化它。