/// ------------------------------------------------------------------------------------ /// <summary> /// This will build a tooltip for a info. bar button that's made up of the title of /// the button's corresponding sidebar tab (i.e. task tab) and -- if the tab is the /// active sidebar tab -- the tab's current button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// ------------------------------------------------------------------------------------ private void infoButton_MouseHover(object sender, EventArgs e) { InformationBarButton button = sender as InformationBarButton; if (button == null || button.Tag == null) { return; } SideBarTab tab = button.Tag as SideBarTab; if (tab == null) { return; } if (tab == sideBarFw.ActiveTab) { button.TooltipText = String.Format(FrameworkStrings.ksInfoBarBtnToolTipFmt, tab.Title, tab.Buttons[tab.IntSelection[0]].Text); } else { button.TooltipText = tab.Title; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Activates the given SideBarButton and perhaps the SideBarTab, if appropriate. This /// is called when the View menu item is clicked. /// </summary> /// <param name="tab">The SideBarTab to make active, if appropriate</param> /// <param name="button">The SideBarButton to make active</param> /// ------------------------------------------------------------------------------------ public void ActivateTabAndButton(SideBarTab tab, SideBarButton button) { CheckDisposed(); int iTab = Tabs.IndexOf(tab); // if we're in ActiveTabIsExclusive mode... if (ActiveTabIsExclusive) { if (m_iActive != iTab) { // Collapse the previous tab and expand the new tab. int iActivePrevious = m_iActive; m_iActive = iTab; SuspendLayout(); Tabs[iActivePrevious].Collapse(); PositionTabs(); ResumeLayout(true); } } // Press the specified button in this tab and clear all others. // REVIEW: What should this do in multiSelect mode when we // want to preserve the state of all the buttons? We would // want to press only the specified button. foreach (SideBarButton btn in Tabs[m_iActive].Buttons) { btn.PressButton(btn == button); } button.PerformClick(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Builds a menu collection for the specified sidebar tab. The collection contains a /// menu item for each button plus a configure item at the end. /// </summary> /// <param name="tab">given sidebar tab</param> /// <returns>array of menu items from sidebar tab</returns> /// ------------------------------------------------------------------------------------ public MenuItem[] BuildMenusForSideBarTab(SideBarTab tab) { List <MenuItem> mnuList = new List <MenuItem>(); // Create a menu item for each button on the sidebar tab. foreach (SideBarButton button in tab.Buttons) { MenuItem menuItem = new MenuItem(button.Text); MenuExtender.AddMenuItem(menuItem); MenuExtender.SetTag(menuItem, button); MenuExtender.SetCommandId(menuItem, "SideBarButtonMenu"); mnuList.Add(menuItem); } // Create the separator MenuItem mnuSepr = new MenuItem("-"); MenuExtender.AddMenuItem(mnuSepr); MenuExtender.SetCommandId(mnuSepr, tab.ConfigureMenuCommandId); MenuExtender.SetTag(mnuSepr, tab); mnuList.Add(mnuSepr); // Create the configure menu item. MenuItem cfgMenuItem = new MenuItem(tab.ConfigureMenuText); MenuExtender.AddMenuItem(cfgMenuItem); MenuExtender.SetCommandId(cfgMenuItem, tab.ConfigureMenuCommandId); MenuExtender.SetImageList(cfgMenuItem, tab.ConfigureMenuImageList); MenuExtender.SetImageIndex(cfgMenuItem, tab.ConfigureMenuImageIndex); MenuExtender.SetTag(cfgMenuItem, tab); mnuList.Add(cfgMenuItem); return(mnuList.ToArray()); }
public Form2(ImageList largeImages, ImageList smallImages) { // // Required for Windows Form Designer support // InitializeComponent(); // Set properties for sidebar m_sideBar.ImageListLarge = largeImages; m_sideBar.ImageListSmall = smallImages; m_sideBar.Persist = false; // Create first side bar tab - each button has own click handler method SideBarTab tab = new SideBarTab(); m_sideBar.Tabs.Add(tab); tab.Title = "Tab"; // First button on first tab m_btn1 = new SideBarButton(); m_btn1.Text = "First button"; m_btn1.Click += new EventHandler(OnButton1Click); m_btn1.ImageIndex = 1; tab.Buttons.Add(m_btn1); // Second button on first tab m_btn2 = new SideBarButton(); m_btn2.Text = "Second button"; m_btn2.Click += new EventHandler(OnButton2Click); m_btn2.ImageIndex = 2; tab.Buttons.Add(m_btn2); // Second side bar tab - one click handler method for all buttons // This tab supports multiple selections with an off button tab = new SideBarTab(); m_sideBar.Tabs.Add(tab); tab.Title = "Other tab"; tab.MultipleSelections = true; tab.FirstButtonExclusive = true; tab.ButtonClickEvent += new EventHandler(OnGenericButtonClick); // First button on second tab m_btn3 = new SideBarButton(); m_btn3.Text = "Off"; m_btn3.ImageIndex = 3; tab.Buttons.Add(m_btn3); // Second button on second tab m_btn4 = new SideBarButton(); m_btn4.Text = "Button 2"; m_btn4.ImageIndex = 4; tab.Buttons.Add(m_btn4); // Third button on second tab m_btn5 = new SideBarButton(); m_btn5.Text = "Button 3"; m_btn5.ImageIndex = 5; tab.Buttons.Add(m_btn5); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Activates the given SideBarTab. This method is an event handler for a SideBarTab's /// Activate event (a custom event). /// </summary> /// <param name="tab">The new active SideBarTab</param> /// ------------------------------------------------------------------------------------ public void ActivateTab(SideBarTab tab) { CheckDisposed(); int nTab = Tabs.IndexOf(tab); ActivateTab(nTab); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Refresh each info bar button's icon to reflect the current selection within that /// button's associated sidebar tab. /// </summary> /// ------------------------------------------------------------------------------------ public void RefreshInfoBarButtons() { foreach (InformationBarButton button in informationBar.Buttons) { SideBarTab tab = button.Tag as SideBarTab; if (tab != null && tab.IntSelection.Length > 0) { button.ImageIndex = tab.Buttons[tab.IntSelection[0]].ImageIndex; // use the first selection } else { button.ImageIndex = sideBarFw.ImageListSmall.Images.Count - 1; // default to last image } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// The tab is about to be inserted to the task bar tab control. Insert it also to the /// controls collection.. /// </summary> /// ------------------------------------------------------------------------------------ private void OnTabInserting(int index, object value) { SideBarTab tab = value as SideBarTab; if (tab != null) { tab.CalculateDispRect(); tab.Left = SystemInformation.Border3DSize.Width; tab.Width = this.Width - 2 * SystemInformation.Border3DSize.Width; tab.Activate += new SideBarTab.ActivateEventHandler(ActivateTab); tab.Persist = m_fPersist; tab.Collapse(); Controls.Add(tab); Controls.SetChildIndex(tab, Tabs.Count); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// When a sidebar button is clicked update the info bar text and info. button for /// the new current sidebar button. /// </summary> /// /// <param name='sender'>The SideBar tab button that was clicked.</param> /// <param name='e'>The event that caused this function to be called.</param> /// ----------------------------------------------------------------------------------- private void tabButton_Click(object sender, System.EventArgs e) { SideBarButton sideBarButton = (SideBarButton)sender; SideBarTab sideBarTab = (SideBarTab)sideBarButton.Parent.Parent; // Update the info bar caption informationBar.InfoBarLabel.Text = sideBarTab.Title + ' ' + sideBarButton.Text; // find the info bar button associated with the sidebar tab and set the // button's icon to the sidebar button's icon. foreach (InformationBarButton button in informationBar.Buttons) { // Update the info bar button's image if ((SideBarTab)button.Tag == sideBarTab) { button.ImageIndex = sideBarButton.ImageIndex; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// This will trap clicks on the info. bar buttons and build a context menu containing /// one item for each side bar button in the corresponding sidebar tab. It will also /// add a title item with the corresponding tab's title. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// ------------------------------------------------------------------------------------ private void infoButton_Click(object sender, EventArgs e) { InformationBarButton button = sender as InformationBarButton; if (button == null || button.Tag == null) { return; } SideBarTab tab = button.Tag as SideBarTab; if (tab == null) { return; } if (m_cmnuInfoBarButton == null) { m_cmnuInfoBarButton = new ContextMenu(); } else { // Clear the menus items so that we start fresh the next time the // user clicks on the information bar button. foreach (MenuItem menuItem in m_cmnuInfoBarButton.MenuItems) { MenuExtender.ClearMenuItem(menuItem); } m_cmnuInfoBarButton.MenuItems.Clear(); } // Load the context menu m_cmnuInfoBarButton.MenuItems.Add(new LabelMenuItem(tab.Title)); m_cmnuInfoBarButton.MenuItems.AddRange(BuildMenusForSideBarTab(tab)); MenuExtender.AddContextMenu(m_cmnuInfoBarButton); // Popup the loaded ContextMenu just below the button. m_cmnuInfoBarButton.Show(button, new Point(0, button.Bottom)); }
/// <summary> /// <para> Removes a specific <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> from the /// <see cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection'/> .</para> /// </summary> /// <param name='value'>The <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> to remove from the <see cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection'/> .</param> /// <returns><para>None.</para></returns> /// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception> public void Remove(SideBarTab value) { CheckDisposed(); List.Remove(value); }
/// <summary> /// <para>Inserts a <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> into the <see cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection'/> at the specified index.</para> /// </summary> /// <param name='index'>The zero-based index where <paramref name='value'/> should be inserted.</param> /// <param name=' value'>The <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> to insert.</param> /// <returns><para>None.</para></returns> /// <seealso cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection.Add'/> public void Insert(int index, SideBarTab value) { CheckDisposed(); List.Insert(index, value); }
/// <summary> /// <para>Returns the index of a <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> in /// the <see cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection'/> .</para> /// </summary> /// <param name='value'>The <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> to locate.</param> /// <returns> /// <para>The index of the <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> of <paramref name='value'/> in the /// <see cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection'/>, if found; otherwise, -1.</para> /// </returns> /// <seealso cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection.Contains'/> public int IndexOf(SideBarTab value) { CheckDisposed(); return(List.IndexOf(value)); }
/// <summary> /// <para>Gets a value indicating whether the /// <see cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection'/> contains the specified <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/>.</para> /// </summary> /// <param name='value'>The <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> to locate.</param> /// <returns> /// <para><see langword='true'/> if the <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> is contained in the collection; /// otherwise, <see langword='false'/>.</para> /// </returns> /// <seealso cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection.IndexOf'/> public bool Contains(SideBarTab value) { CheckDisposed(); return(List.Contains(value)); }
/// <summary> /// <para>Adds a <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> with the specified value to the /// <see cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection'/> .</para> /// </summary> /// <param name='value'>The <see cref='SIL.FieldWorks.Common.Controls.SideBarTab'/> to add.</param> /// <returns> /// <para>The index at which the new element was inserted.</para> /// </returns> /// <seealso cref='SIL.FieldWorks.Common.Controls.SideBarTabCollection.AddRange(SIL.FieldWorks.Common.Controls.SideBarTab[])'/> public int Add(SideBarTab value) { CheckDisposed(); return(List.Add(value)); }