/// <summary> /// 追加ボタンがクリックされた時に通知を受け取る。 /// </summary> /// <param name="sender">送信元オブジェクト</param> /// <param name="e">イベントオブジェクト</param> private void OnButtonAddProfileClick(object sender, EventArgs e) { DataActorProfile actorProfile = GetSelectedActorProfile(); if (actorProfile == null) { return; } Profile profile = new Profile(); actorProfile.Profiles.Add(profile); TabPage tabPage = new TabPage(); tabPage.Controls.Add(new ProfileEditorControl() { Profile = profile, Dock = DockStyle.Fill }); tabControl.TabPages.Add(tabPage); // タブページ名変更 UpdateTabPageNames(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnButtonDeleteProfileClick(object sender, EventArgs e) { DataActorProfile actorProfile = GetSelectedActorProfile(); if (actorProfile == null) { return; } int index = tabControl.SelectedIndex; if ((index >= 0) && (index < tabControl.TabPages.Count)) { actorProfile.Profiles.RemoveAt(index); tabControl.TabPages.Remove(tabControl.TabPages[index]); UpdateTabPageNames(); } }
/// <summary> /// dirからファイルを読み出す。 /// </summary> /// <param name="dir"></param> private void ProcessOpen(string dir) { this.EditingFolder = dir; Properties.Settings.Default.LastOpenDirectory = dir; actorProfiles = DataActorProfileReader.Read(dir); // データテーブルを初期化する。 DataTable dt = (DataTable)(dataGridView.DataSource); dt.Rows.Clear(); for (int i = 1; i < actorProfiles.Count; i++) { DataActorProfile actorProfile = actorProfiles[i]; DataRow row = dt.NewRow(); row[0] = string.Format("{0,4:D}:{1}", actorProfile.Id, actorProfile.Name); // 行にオブジェクト紐付けしたいなあ。 dt.Rows.Add(row); } }
/// <summary> /// データグリッドビューの選択状態が変わったときに通知を受け取る。 /// </summary> /// <param name="sender">送信元オブジェクト</param> /// <param name="e">イベントオブジェクト</param> private void OnDataGridViewSelectionChanged(object sender, EventArgs e) { DataActorProfile actorProfile = GetSelectedActorProfile(); if (actorProfile == null) { // タブページは全部クリア tabControl.TabPages.Clear(); } else { for (int i = 0; i < actorProfile.Profiles.Count; i++) { TabPage tabPage; if (i < tabControl.TabPages.Count) { tabPage = tabControl.TabPages[i]; ProfileEditorControl editor = (ProfileEditorControl)(tabPage.Controls[0]); editor.Profile = actorProfile.Profiles[i]; } else { tabPage = new TabPage(); tabPage.Controls.Add(new ProfileEditorControl() { Profile = actorProfile.Profiles[i], Dock = DockStyle.Fill }); tabControl.TabPages.Add(tabPage); } } // 余計なタブは削除(ちなみに途中を先に消すとIndex例外がでるので後ろから消す) for (int i = tabControl.TabPages.Count - 1; i >= actorProfile.Profiles.Count; i--) { tabControl.TabPages.RemoveAt(i); } UpdateTabPageNames(); } }