Windows フォームの新機能。このエラーを取り除くことはできません。これは、ボタン 1 が Queen クラスやインスタンス 'queen' にリンクされていないためだと思います。その場合、VS のデザイン ビューのボタンのプロパティでそれを行うにはどうすればよいですか? 関連するコードの一部を次に示します。
public Form1()
{
InitializeComponent();
Worker[] workers = new Worker[4];
workers[0] = new Worker(new string[] { "Nectar collector", "Honey manufacturing" });
workers[1] = new Worker(new string[] { "Egg care", "Baby bee tutoring" });
workers[2] = new Worker(new string[] { "Hive maintenance", "Sting patrol" });
workers[3] = new Worker(new string[] { "Nectar collector", "Honey manufacturing", "Egg care",
"Baby bee tutoring", "Hive maintenance", "Sting patrol" });
Queen queen = new Queen(workers);
}
private void button1_Click(object sender, EventArgs e)
{
if (queen.AssignWork(workerBeeJob.Text, (int)shifts.Value) == false)
MessageBox.Show("No workers are available to do the job '" + workerBeeJob.Text +
".' The queen bee says...");
else
MessageBox.Show("The job '" + workerBeeJob.Text + "' will be done in "
+ shifts.Value + " shifts. The queen bee says...");
}
class Queen
{
private Worker[] workers;
private int shiftNumber = 0;
public Queen(Worker[] workers)
{
this.workers = workers;
}
public bool AssignWork(string job, int numberOfShifts)
{
for (int i = 0; i < workers.Length; i++)
if (workers[i].DoThisJob(job, numberOfShifts))
return true;
return false;
}