/// <summary>編集するTimePeriodsオブジェクトを設定する</summary> /// <param name="timePeriods">編集するTimePeriodsオブジェクト</param> public void SetTimePeriods(TimePeriods timePeriods) { //編集中のTimePeriodsオブジェクトがあればイベント通知を解除 if (this.timePeriods != null) { this.timePeriods.NameChangeEvent -= new TimePeriods.NameChangeEventHandler(timePeriods_NameChangeEvent); this.timePeriods.TimePeriodAddEvent -= new TimePeriods.TimePeriodAddEventHandler(timePeriods_TimePeriodAddEvent); this.timePeriods.TimePeriodChangeEvent -= new TimePeriods.TimePeriodChangeEventHandler(timePeriods_TimePeriodChangeEvent); this.timePeriods.TimePeriodRemoveEvent -= new TimePeriods.TimePeriodRemoveEventHandler(timePeriods_TimePeriodRemoveEvent); } //編集中のTimePeriodsオブジェクトを更新 this.timePeriods = timePeriods; //TimePeriodsオブジェクトのイベント通知を受ける timePeriods.NameChangeEvent += new TimePeriods.NameChangeEventHandler(timePeriods_NameChangeEvent); timePeriods.TimePeriodAddEvent += new TimePeriods.TimePeriodAddEventHandler(timePeriods_TimePeriodAddEvent); timePeriods.TimePeriodChangeEvent += new TimePeriods.TimePeriodChangeEventHandler(timePeriods_TimePeriodChangeEvent); timePeriods.TimePeriodRemoveEvent += new TimePeriods.TimePeriodRemoveEventHandler(timePeriods_TimePeriodRemoveEvent); //コントロール削除時にイベント通知を解除 this.Disposed += delegate(object sender, EventArgs e) { timePeriods.NameChangeEvent -= new TimePeriods.NameChangeEventHandler(timePeriods_NameChangeEvent); timePeriods.TimePeriodAddEvent -= new TimePeriods.TimePeriodAddEventHandler(timePeriods_TimePeriodAddEvent); timePeriods.TimePeriodChangeEvent -= new TimePeriods.TimePeriodChangeEventHandler(timePeriods_TimePeriodChangeEvent); timePeriods.TimePeriodRemoveEvent -= new TimePeriods.TimePeriodRemoveEventHandler(timePeriods_TimePeriodRemoveEvent); }; //リストボックスを初期化 lbxTimePeriods.Items.Clear(); for (int i = 0; i < timePeriods.Count; i++) lbxTimePeriods.Items.Add(timePeriods.GetTimePeriodName(i)); //時間帯が一つの場合は削除ボタンを操作不能にする if (lbxTimePeriods.Items.Count <= 1) btnRemove.Enabled = false; //一つ目の時間帯を選択 if (0 < lbxTimePeriods.Items.Count) lbxTimePeriods.SelectedIndex = 0; //Seasonsの名称を設定 initializing = true; tbxTimePeriodsName.Text = timePeriods.Name; initializing = false; }