/// <summary> /// Builds a menu based on the parameters given /// </summary> /// <typeparam name="T">The type of data the menu should hold</typeparam> /// <param name="parentControl">The parent control this menu resides in</param> /// <param name="appearance">The appearance of the menu<para>Leave null for default values</para></param> /// <param name="menuDrawer">The menu drawer to use when the menu needs to be drawn</param> /// <param name="tabDrawer">The tab drawer to use when a tab needs to be drawn</param> /// <param name="clickHandler">The click handler to use with the menu</param> /// <param name="locationDrawer">The location drawer the tab uses to finalize location dependent tab visuals</param> /// <param name="eventFunction">The function to execute when the tab changes</param> /// <returns>A Menu that conforms to the given parameters</returns> public static IMenu <T> Build <T>(Control parentControl, MenuAppearance appearance = null, IMenuDrawer menuDrawer = null, ITabDrawer tabDrawer = null, IClickHandler clickHandler = null, ITabLocationDrawer locationDrawer = null, EventHandler <TabChangedEventArgs <T> > eventFunction = null) { var menu = new Menu <T> { appearance = appearance ?? MenuAppearance.GetDefaultAppearance(), allowRightClick = false, parentControl = parentControl, currentTabIndex = -1, currentMouseMode = MouseModes.mouseClick, menuDrawer = menuDrawer ?? new VerticalMenuDrawer(), tabDrawer = tabDrawer ?? new VerticalTabDrawer(), clickHandler = clickHandler ?? new VerticalClickHandler(), }; parentControl.Paint += menu.OnDraw; parentControl.MouseClick += menu.OnClick; if (locationDrawer != null) { menu.tabDrawer.tabLocationDrawer = locationDrawer; } if (eventFunction != null) { menu.tabChanged += eventFunction; } return(menu); }
/// <summary> /// Draws the menu to a graphics instance /// </summary> /// <param name="g">The graphics instance to draw to</param> /// <param name="appearance">The appearance data of the menu</param> /// <param name="menuSize">The size of the menu</param> /// <param name="tabList">The list of tabs to draw</param> /// <param name="tabDrawer">The tab drawer to use when drawing the tabs</param> public void Draw <T>(Graphics g, MenuAppearance appearance, Size menuSize, IList <ITab <T> > tabList, ITabDrawer tabDrawer) { if (appearance.borderWidth > 0) { using Pen pen = new Pen(appearance.borderColor, appearance.borderWidth); g.DrawRectangle(pen, new Rectangle(0, 0, menuSize.Width - 1, menuSize.Height - 1)); } for (int i = 0, y = 0; i < tabList.Count(); i++, y += appearance.tabSize.Height) { tabDrawer.Draw(g, appearance, tabList[i], new Point(0, y), i == 0, i == (tabList.Count - 1)); } }