/* * InsertTabPage */ private void InsertTabPage(int index, NuGenTabPage tabPageToInsert) { Debug.Assert(tabPageToInsert != null, "tabPageToInsert != null"); this.InsertTabButton(index, this.InitializeTabPage(tabPageToInsert)); this.OnTabPageAdded( new NuGenCollectionEventArgs <NuGenTabPage>(index, tabPageToInsert) ); }
/* * AddTabPage */ private void AddTabPage(NuGenTabPage tabPageToAdd) { Debug.Assert(tabPageToAdd != null, "tabPageToAdd != null"); this.AddTabButton(this.InitializeTabPage(tabPageToAdd)); this.OnTabPageAdded( new NuGenCollectionEventArgs <NuGenTabPage>(this.TabPages.Count - 1, tabPageToAdd) ); }
private void tabPage_TextChanged(object sender, EventArgs e) { Debug.Assert(sender is NuGenTabPage, "sender is NuGenTabPage"); NuGenTabPage tabPage = (NuGenTabPage)sender; Debug.Assert(this.PageButtonDictionary.ContainsKey(tabPage), "this.PageButtonDictionary.ContainsKey(tabPage)"); this.PageButtonDictionary[tabPage].Text = tabPage.Text; }
/// <summary> /// Initializes a new instance of the <see cref="NuGenTabCancelEventArgs"/> class. /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="tabPage"/> is <see langword="null"/>. /// </para> /// </exception> public NuGenTabCancelEventArgs(NuGenTabPage tabPage, bool cancel) { if (tabPage == null) { throw new ArgumentNullException("tabPage"); } _tabPage = tabPage; _cancel = cancel; }
/* * Remove */ /// <summary> /// </summary> /// <param name="tabPageToRemove"></param> /// <returns></returns> public bool Remove(NuGenTabPage tabPageToRemove) { if (_list.Contains(tabPageToRemove)) { Debug.Assert(_tabControl != null, "_tabControl != null"); _tabControl.Controls.Remove(tabPageToRemove); return(_list.Remove(tabPageToRemove)); } return(false); }
/// <summary> /// </summary> /// <param name="text"></param> /// <param name="tabButtonImage">Can be <see langword="null"/>.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="text"/> is <see langword="null"/>. /// </para> /// </exception> public NuGenTabPage Add(string text, Image tabButtonImage) { Debug.Assert(_tabControl != null, "_tabControl != null"); Debug.Assert(_tabControl.ServiceProvider != null, "_tabControl.ServiceProvider != null"); NuGenTabPage tabPage = new NuGenTabPage(_tabControl.ServiceProvider); tabPage.TabButtonImage = tabButtonImage; this.Add(tabPage); tabPage.Text = text; return(tabPage); }
private void tabButton_SelectedChanged(object sender, EventArgs e) { Debug.Assert(sender is NuGenTabButton, "sender is NuGenTabButton"); NuGenTabButton tabButton = (NuGenTabButton)sender; if (tabButton.Selected) { Debug.Assert(this.ButtonPageDictionary.ContainsKey(tabButton), "this.ButtonPageDictionary.ContainsKey(tabButton)"); NuGenTabPage activeTabPage = this.ButtonPageDictionary[tabButton]; Debug.Assert(activeTabPage != null, "activeTabPage != null"); activeTabPage.BringToFront(); } }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="tabPageToAdd"/> is <see langword="null"/>. /// </para> /// </exception> public int Add(NuGenTabPage tabPageToAdd) { if (tabPageToAdd == null) { throw new ArgumentNullException("tabPageToAdd"); } Debug.Assert(_tabControl != null, "_tabControl != null"); _list.Add(tabPageToAdd); _tabControl.AddTabPage(tabPageToAdd); return(_list.Count - 1); }
private void tabButton_Close(object sender, EventArgs e) { Debug.Assert(sender is NuGenTabButton, "sender is NuGenTabButton"); Debug.Assert(this.ButtonPageDictionary.ContainsKey((NuGenTabButton)sender), "this.ButtonPageDictionary.ContainsKey((NuGenTabButton)sender)"); NuGenTabPage tabPage = this.ButtonPageDictionary[(NuGenTabButton)sender]; NuGenTabCancelEventArgs eventArgs = new NuGenTabCancelEventArgs(tabPage); this.OnTabCloseButtonClick(eventArgs); if (!eventArgs.Cancel) { this.TabPages.Remove(this.ButtonPageDictionary[(NuGenTabButton)sender]); } }
/* * OnControlRemoved */ /// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.ControlRemoved"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.ControlEventArgs"></see> that contains the event data.</param> protected override void OnControlRemoved(ControlEventArgs e) { base.OnControlRemoved(e); if (e.Control is NuGenTabPage) { NuGenTabPage tabPage = (NuGenTabPage)e.Control; int index = this.TabPages.IndexOf(tabPage); this.RemoveTabPage(tabPage); if (this.TabPages.ListInternal.Remove(tabPage)) { this.OnTabPageRemoved(new NuGenCollectionEventArgs <NuGenTabPage>(index, tabPage)); } } }
/* * RemoveTabPage */ private void RemoveTabPage(NuGenTabPage tabPageToRemove) { Debug.Assert(tabPageToRemove != null, "tabPageToRemove != null"); NuGenTabButton associatedTabButton = this.PageButtonDictionary[tabPageToRemove]; Debug.Assert(associatedTabButton != null, "associatedTabButton != null"); tabPageToRemove.EnabledChanged -= this.tabPage_EnabledChanged; tabPageToRemove.TabButtonImageChanged -= this.tabPage_TabButtonImageChanged; tabPageToRemove.TextChanged -= this.tabPage_TextChanged; this.ButtonPageDictionary.Remove(associatedTabButton); this.PageButtonDictionary.Remove(tabPageToRemove); this.RemoveTabButton(associatedTabButton); }
/* * AddTabPage */ /// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="pageContent"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="text"/> is <see langword="null"/>. /// </para> /// </exception> public NuGenTabPage AddTabPage(Control pageContent, string text, Image tabButtonImage) { if (pageContent == null) { throw new ArgumentNullException("pageContent"); } if (text == null) { throw new ArgumentNullException("text"); } NuGenTabPage tabPage = this.TabPages.Add(text, tabButtonImage); tabPage.Controls.Add(pageContent); return(tabPage); }
/* * Indexer */ /// <summary> /// </summary> /// <param name="zeroBasedIndex"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="zeroBasedIndex"/> should be within the bounds of the collection. /// </exception> public NuGenTabPage this[int zeroBasedIndex] { get { NuGenTabPage tabPage = null; try { tabPage = _list[zeroBasedIndex]; } catch (ArgumentOutOfRangeException e) { throw e; } return(tabPage); } }
/// <summary> /// </summary> /// <param name="index"></param> /// <param name="text"></param> /// <param name="tabButtonImage"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="text"/> is <see langword="null"/>. /// </para> /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <para> /// <paramref name="index"/> must be within the bounds of the collection. /// </para> /// </exception> public NuGenTabPage Insert(int index, string text, Image tabButtonImage) { if (text == null) { throw new ArgumentNullException("text"); } Debug.Assert(_tabControl != null, "_tabControl != null"); Debug.Assert(_tabControl.ServiceProvider != null, "_tabControl.ServiceProvider != null"); NuGenTabPage tabPage = new NuGenTabPage(_tabControl.ServiceProvider); tabPage.TabButtonImage = tabButtonImage; this.Insert(index, tabPage); tabPage.Text = text; return(tabPage); }
/// <summary> /// </summary> /// <param name="index"></param> /// <param name="tabPageToInsert"></param> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="tabPageToInsert"/> is <see langword="null"/>. /// </para> /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <para> /// <paramref name="index"/> must be within the bounds of the collection. /// </para> /// </exception> public void Insert(int index, NuGenTabPage tabPageToInsert) { if (tabPageToInsert == null) { throw new ArgumentNullException("tabPageToInsert"); } Debug.Assert(_tabControl != null, "_tabControl != null"); try { _list.Insert(index, tabPageToInsert); _tabControl.InsertTabPage(index, tabPageToInsert); } catch (ArgumentOutOfRangeException e) { throw e; } }
private void tabPage_EnabledChanged(object sender, EventArgs e) { Debug.Assert(sender is NuGenTabPage, "sender is NuGenTabPage"); NuGenTabPage tabPage = (NuGenTabPage)sender; Debug.Assert(this.PageButtonDictionary.ContainsKey(tabPage), "this.PageButtonDictionary.ContainsKey(tabPage)"); NuGenTabButton tabButton = this.PageButtonDictionary[tabPage]; tabButton.Enabled = tabPage.Enabled; tabButton.Invalidate(true); if ( !tabPage.Enabled && tabPage == this.SelectedTab ) { NuGenTabPage newSelectedTabPage = null; for (int i = this.SelectedIndex - 1; i > -1; i--) { if (this.TabPages[i].Enabled) { newSelectedTabPage = this.TabPages[i]; } } if (newSelectedTabPage == null) { for (int i = this.SelectedIndex + 1; i < this.TabPages.Count; i++) { if (this.TabPages[i].Enabled) { newSelectedTabPage = this.TabPages[i]; } } } this.SelectedTab = newSelectedTabPage; } }
/* * InitializeTabPage */ private NuGenTabButton InitializeTabPage(NuGenTabPage tabPageToInitialize) { Debug.Assert(tabPageToInitialize != null, "tabPageToInitialize != null"); Debug.Assert(this.ServiceProvider != null, "this.ServiceProvider != null"); NuGenTabButton tabButtonToAssociate = new NuGenTabButton(this.ServiceProvider); tabButtonToAssociate.Image = tabPageToInitialize.TabButtonImage; tabButtonToAssociate.Text = tabPageToInitialize.Text; this.ButtonPageDictionary.Add(tabButtonToAssociate, tabPageToInitialize); this.PageButtonDictionary.Add(tabPageToInitialize, tabButtonToAssociate); tabPageToInitialize.EnabledChanged += this.tabPage_EnabledChanged; tabPageToInitialize.TabButtonImageChanged += this.tabPage_TabButtonImageChanged; tabPageToInitialize.TextChanged += this.tabPage_TextChanged; this.Controls.Add(tabPageToInitialize); tabPageToInitialize.BringToFront(); return(tabButtonToAssociate); }
/// <summary> /// Initializes a new instance of the <see cref="NuGenTabCancelEventArgs"/> class.<para/> /// Cancel = <see langword="false"/>. /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="tabPage"/> is <see langword="null"/>. /// </para> /// </exception> public NuGenTabCancelEventArgs(NuGenTabPage tabPage) : this(tabPage, false) { }
/// <summary> /// </summary> /// <param name="text"></param> /// <param name="tabButtonImage">Can be <see langword="null"/>.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="text"/> is <see langword="null"/>. /// </para> /// </exception> public NuGenTabPage Add(string text, Image tabButtonImage) { Debug.Assert(_tabControl != null, "_tabControl != null"); Debug.Assert(_tabControl.ServiceProvider != null, "_tabControl.ServiceProvider != null"); NuGenTabPage tabPage = new NuGenTabPage(_tabControl.ServiceProvider); tabPage.TabButtonImage = tabButtonImage; this.Add(tabPage); tabPage.Text = text; return tabPage; }
/* * InsertTabPage */ private void InsertTabPage(int index, NuGenTabPage tabPageToInsert) { Debug.Assert(tabPageToInsert != null, "tabPageToInsert != null"); this.InsertTabButton(index, this.InitializeTabPage(tabPageToInsert)); this.OnTabPageAdded( new NuGenCollectionEventArgs<NuGenTabPage>(index, tabPageToInsert) ); }
/* * AddTabPage */ private void AddTabPage(NuGenTabPage tabPageToAdd) { Debug.Assert(tabPageToAdd != null, "tabPageToAdd != null"); this.AddTabButton(this.InitializeTabPage(tabPageToAdd)); this.OnTabPageAdded( new NuGenCollectionEventArgs<NuGenTabPage>(this.TabPages.Count - 1, tabPageToAdd) ); }
/* * IndexOf */ /// <summary> /// </summary> /// <param name="tabPage"></param> /// <returns></returns> public int IndexOf(NuGenTabPage tabPage) { return _list.IndexOf(tabPage); }
/* * Remove */ /// <summary> /// </summary> /// <param name="tabPageToRemove"></param> /// <returns></returns> public bool Remove(NuGenTabPage tabPageToRemove) { if (_list.Contains(tabPageToRemove)) { Debug.Assert(_tabControl != null, "_tabControl != null"); _tabControl.Controls.Remove(tabPageToRemove); return _list.Remove(tabPageToRemove); } return false; }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="tabPageToAdd"/> is <see langword="null"/>. /// </para> /// </exception> public int Add(NuGenTabPage tabPageToAdd) { if (tabPageToAdd == null) { throw new ArgumentNullException("tabPageToAdd"); } Debug.Assert(_tabControl != null, "_tabControl != null"); _list.Add(tabPageToAdd); _tabControl.AddTabPage(tabPageToAdd); return _list.Count - 1; }
/* * Contains */ /// <summary> /// </summary> /// <param name="tabPage"></param> /// <returns></returns> public bool Contains(NuGenTabPage tabPage) { return _list.Contains(tabPage); }
/* * CopyTo */ /// <summary> /// Copies the entire contents of this collection to a compatible one-dimensional /// <see cref="T:System.Array"></see>, starting at the specified index of the target array. /// </summary> /// <exception cref="T:System.InvalidCastException"> /// The type of the source element cannot be cast automatically to the type of array. /// </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// index is less than 0. /// </exception> /// <exception cref="T:System.ArgumentException"> /// <para> /// <paramref name="destination"/> is multidimensional. /// </para> /// -or- /// <para> /// <paramref name="zeroBasedIndexToStartAt"/> is equal to or greater than the length of /// the destination array. /// </para> /// -or- /// <para> /// The number of elements in the source collection is greater /// than the available space from index to the end of the destination array. /// </para> /// </exception> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="destination"/> is <see langword="null"/>. /// </exception> public void CopyTo(NuGenTabPage[] destination, int zeroBasedIndexToStartAt) { _list.CopyTo(destination, zeroBasedIndexToStartAt); }
/* * Contains */ /// <summary> /// </summary> /// <param name="tabPage"></param> /// <returns></returns> public bool Contains(NuGenTabPage tabPage) { return(_list.Contains(tabPage)); }
/* * InitializeTabPage */ private NuGenTabButton InitializeTabPage(NuGenTabPage tabPageToInitialize) { Debug.Assert(tabPageToInitialize != null, "tabPageToInitialize != null"); Debug.Assert(this.ServiceProvider != null, "this.ServiceProvider != null"); NuGenTabButton tabButtonToAssociate = new NuGenTabButton(this.ServiceProvider); tabButtonToAssociate.Image = tabPageToInitialize.TabButtonImage; tabButtonToAssociate.Text = tabPageToInitialize.Text; this.ButtonPageDictionary.Add(tabButtonToAssociate, tabPageToInitialize); this.PageButtonDictionary.Add(tabPageToInitialize, tabButtonToAssociate); tabPageToInitialize.EnabledChanged += this.tabPage_EnabledChanged; tabPageToInitialize.TabButtonImageChanged += this.tabPage_TabButtonImageChanged; tabPageToInitialize.TextChanged += this.tabPage_TextChanged; this.Controls.Add(tabPageToInitialize); tabPageToInitialize.BringToFront(); return tabButtonToAssociate; }
/* * IndexOf */ /// <summary> /// </summary> /// <param name="tabPage"></param> /// <returns></returns> public int IndexOf(NuGenTabPage tabPage) { return(_list.IndexOf(tabPage)); }
/// <summary> /// </summary> /// <param name="index"></param> /// <param name="text"></param> /// <param name="tabButtonImage"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="text"/> is <see langword="null"/>. /// </para> /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <para> /// <paramref name="index"/> must be within the bounds of the collection. /// </para> /// </exception> public NuGenTabPage Insert(int index, string text, Image tabButtonImage) { if (text == null) { throw new ArgumentNullException("text"); } Debug.Assert(_tabControl != null, "_tabControl != null"); Debug.Assert(_tabControl.ServiceProvider != null, "_tabControl.ServiceProvider != null"); NuGenTabPage tabPage = new NuGenTabPage(_tabControl.ServiceProvider); tabPage.TabButtonImage = tabButtonImage; this.Insert(index, tabPage); tabPage.Text = text; return tabPage; }
/* * SelectTab */ /// <summary> /// </summary> /// <param name="tabPageToSelect"></param> public void SelectTab(NuGenTabPage tabPageToSelect) { this.SelectedTab = tabPageToSelect; }
/* * RemoveAt */ /// <summary> /// </summary> /// <param name="zeroBasedIndex"></param> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="zeroBasedIndex"/> should be within the bounds of the collection. /// </exception> public void RemoveAt(int zeroBasedIndex) { NuGenTabPage tabPage = this[zeroBasedIndex]; this.Remove(tabPage); }