不包含发票的定义?

时间:2015-04-02 01:24:10

标签: c# forms

我尝试从表单1到表单2进行数据传输但是即使我在项目中添加了Invoice.cs类,它也会抛出错误。

抛出错误:

  

' System.Windows.Forms.Form中'不包含'发票'的定义没有延期方式'发票'接受类型为'System.Windows.Forms.Form'的第一个参数。可以找到(你错过了使用指令或程序集引用吗?)

表格1

private void button5_Click(object sender, EventArgs e)
    {
        Form InvoiceSystem = new Form();
        if (InvoiceSystem == null)
        {
            Invoice invoice = new Invoice();
            invoice.id = Convert.ToInt16(textId.Text);
            invoice.nameItem = textNameiTem.Text;
            invoice.priceItem = Convert.ToDouble(textPrice.Text);
            invoice.qty = Convert.ToInt16(textQty.Text);
            invoice.amount = Convert.ToDouble(textAmount.Text);
            invoice.date = Convert.ToInt16(textDate.Text);
            invoice.invoiceNo = Convert.ToInt16(textInvoice.Text);
            InvoiceSystem.Invoice = invoice;
            InvoiceSystem.Show();
        }
    }

表格2

  public partial class InvoiceSystem : Form
        {
            public Invoice Invoice
            {
              set
        {
            textId.Text = value.id.ToString();
            textitem.Text = value.nameItem;
            textPrice.Text = value.priceItem.ToString();
            textQty.Text = value.qty.ToString();
            textAmt.Text = value.amount.ToString();
            textdate.Text = value.date.ToString();
            textInvoiceNo.Text = value.invoiceNo.ToString();
        }
    }

在Invoice.cs类

public class Invoice
{
    public int id {get;set;}
    public string nameItem { get; set; }
    public double priceItem{get;set;}
    public int qty { get; set; }
    public double amount { get; set; }
    public int date { get; set; }
    public int invoiceNo { get; set; }
}

1 个答案:

答案 0 :(得分:2)

您已将变量声明为Form

Form InvoiceSystem = new Form();

Form本身没有任何自定义设置。它是构建在框架中的所有表单的基类。您的自定义类是InvoiceSystem,您已将其作为特定类型的表单。使用:

InvoiceSystem invoiceSystem = new InvoiceSystem();

(另请注意,我将变量名称设置为小写。因此,您还需要更新引用该变量的其他代码行。不要使用与您的类相同的名称命名变量。导致混淆。)


另请注意,您的if声明是多余的:

Form InvoiceSystem = new Form();
if (InvoiceSystem == null)
//...

紧接在前的行实例化了该变量。因此该变量在下一行永远不会<{1}}。