cs1061 Form1不包含Form1_load的定义,也没有可访问的方法Form1_load接受Form1类型的第一个参数。

问题描述:

使用System;

使用System.Collections.Generic;

使用System.ComponentModel;

使用System.Data;

使用System.Drawing;

使用System.Linq;

使用System.Text;

使用System.Threading.Tasks ;
$
使用System.Windows.Forms;

使用静态System.Windows.Forms.VisualStyles.VisualStyleElement;



namespace第12章_ClassesLab

{

    //在此声明居民名单。 

   班级居民

    {

        private int tagNumber;

       私人字符串名称;

       私人字符串类型;

       公共居民()

        {

            tagNumber = 0;

            name =" None";

            type =" None";

        }¥b $ b        public Resident(int tagNumber,String name,string type)

        {

            this.tagNumber = tagNumber;

            this.name = name;

            this.type = type;

        }¥b $ b        public int TagNumber

        {

           得到
            {

                return tagNumber;

            }¥b $ b           设为

            {

                tagNumber = value;

            }¥b $ b        }¥b $ b       公共字符串名称

        {

           得到
            {

               返回姓名;

            }¥b $ b           设为

            {

                name = value;

            }¥b $ b        }¥b $ b       公共字符串类型

        {

           得到
            {

               退货类型;

            }¥b $ b           设为

            {

                type = value;

            }¥b $ b        }¥b $ b        public string GetDisplayText()

        {

           返回"标记#" + tagNumber +",名称:" + name +",Type" + type +" \ n";

        }¥b $ b    }


   公共部门类Form1:表格

    {

  &NBSP; &NBSP; &NBSP;私人清单<居民>居民=新名单<居民>();



  &NBSP; &NBSP; &NBSP;居民; b
  &NBSP; &NBSP; &NBSP; public Form1()

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; InitializeComponent();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; lblResidentCount.Enabled = false;

  &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; private void btnAdd_Click(object sender,EventArgs e)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;居民=新居民();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; resident.TagNumber = Convert.ToInt32(txtTagNumber.Text);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; resident.Name = txtName.Text;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; resident.Type = Combobox1.SelectedItem.ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; resident.Add(居民);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; lblResidentCount.Text = residents.Count.ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; txtName.Text ="&quot ;;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; txtTagNumber.Text ="&quot ;;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MessageBox.Show("已成功添加");

  &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; private void btnDisplay_Click(object sender,EventArgs e)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string result ="&quot ;;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; foreach(居民居民)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; result = result + r.GetDisplayText();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MessageBox.Show(结果,"居民");

  &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; private void btnEvictAll_Click(object sender,EventArgs e)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; resident.Clear();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; lblResidentCount.Text = residents.Count.ToString();

  &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Chapter12_ClassesLab
{
    // declare the list of residents here. 
    class Resident
    {
        private int tagNumber;
        private string name;
        private string type;
        public Resident()
        {
            tagNumber = 0;
            name = "None";
            type = "None";
        }
        public Resident(int tagNumber, String name, string type)
        {
            this.tagNumber = tagNumber;
            this.name = name;
            this.type = type;
        }
        public int TagNumber
        {
            get
            {
                return tagNumber;
            }
            set
            {
                tagNumber = value;
            }
        }
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
        public string Type
        {
            get
            {
                return type;
            }
            set
            {
                type = value;
            }
        }
        public string GetDisplayText()
        {
            return "Tag# " + tagNumber + ", Name: " + name + ", Type " + type + "\n";
        }
    }

    public partial class Form1 : Form
    {
        private List<Resident> residents = new List<Resident>();

        Resident resident;
        public Form1()
        {
            InitializeComponent();
            lblResidentCount.Enabled = false;
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            resident = new Resident();
            resident.TagNumber = Convert.ToInt32(txtTagNumber.Text);
            resident.Name = txtName.Text;
            resident.Type = Combobox1.SelectedItem.ToString();
            residents.Add(resident);

            lblResidentCount.Text = residents.Count.ToString();
            txtName.Text = "";
            txtTagNumber.Text = "";
            MessageBox.Show("Added Successfully");
        }
        private void btnDisplay_Click(object sender, EventArgs e)
        {
            string result = "";
            foreach (Resident r in residents)
            {
                result = result + r.GetDisplayText();
            }
            MessageBox.Show(result, "Residents");
        }
        private void btnEvictAll_Click(object sender, EventArgs e)
        {
            residents.Clear();
            lblResidentCount.Text = residents.Count.ToString();
        }
    }
}

查看设计器生成的文件。您已单击以添加on load事件。删除事件和表单代码时,不会删除此代码。在那里你需要删除仍然指向加载方法中现在缺失的事件接线代码。
Take a look at the designer generated file. You have clicked to add an on load event. This code is not removed, when you delete the event and the form code. There you need to remove the event wiring code which still points to the now missing on load method.