Example #1
0
        /// <summary>編集するSeasonsオブジェクトを設定する</summary>
        /// <param name="seasons">編集するSeasonsオブジェクト</param>
        public void SetSeasons(Seasons seasons)
        {
            //編集中のseasonsオブジェクトがあればイベント通知を解除
            if (this.seasons != null)
            {
                this.seasons.NameChangeEvent -= new Seasons.NameChangeEventHandler(seasons_NameChangeEvent);
                this.seasons.SeasonAddEvent -= new Seasons.SeasonAddEventHandler(seasons_SeasonAddEvent);
                this.seasons.SeasonChangeEvent -= new Seasons.SeasonChangeEventHandler(seasons_SeasonChangeEvent);
                this.seasons.SeasonRemoveEvent -= new Seasons.SeasonRemoveEventHandler(seasons_SeasonRemoveEvent);
            }
            //編集中のseasonsオブジェクトを更新
            this.seasons = seasons;

            //Seasonsオブジェクトのイベント通知を受ける
            seasons.NameChangeEvent += new Seasons.NameChangeEventHandler(seasons_NameChangeEvent);
            seasons.SeasonAddEvent += new Seasons.SeasonAddEventHandler(seasons_SeasonAddEvent);
            seasons.SeasonChangeEvent += new Seasons.SeasonChangeEventHandler(seasons_SeasonChangeEvent);
            seasons.SeasonRemoveEvent += new Seasons.SeasonRemoveEventHandler(seasons_SeasonRemoveEvent);

            //コントロール削除時にイベント通知を解除
            this.Disposed += delegate(object sender, EventArgs e) {
                seasons.NameChangeEvent -= new Seasons.NameChangeEventHandler(seasons_NameChangeEvent);
                seasons.SeasonAddEvent -= new Seasons.SeasonAddEventHandler(seasons_SeasonAddEvent);
                seasons.SeasonChangeEvent -= new Seasons.SeasonChangeEventHandler(seasons_SeasonChangeEvent);
                seasons.SeasonRemoveEvent -= new Seasons.SeasonRemoveEventHandler(seasons_SeasonRemoveEvent);
            };

            //リストボックスを初期化
            lbxSeasons.Items.Clear();
            for (int i = 0; i < seasons.Count; i++) lbxSeasons.Items.Add(seasons.GetSeasonName(i));
            //季節が一つの場合は削除ボタンを操作不能にする
            if (lbxSeasons.Items.Count <= 1) btnRemove.Enabled = false;
            //一つ目の季節を選択
            if (0 < lbxSeasons.Items.Count) lbxSeasons.SelectedIndex = 0;

            //Seasonsの名称を設定
            initializing = true;
            tbxSeasonsName.Text = seasons.Name;
            initializing = false;
        }