/// <summary> /// Called when [calculate tab page]. /// </summary> /// <param name="g">The g.</param> /// <param name="currentItem">The current item.</param> private void OnCalcTabPage(Graphics g, ZeroitFameyeTabStripItem currentItem) { Font currentFont = Font; if (currentItem == SelectedItem) { currentFont = new Font(Font, FontStyle.Bold); } SizeF textSize = g.MeasureString(currentItem.Title, currentFont, new SizeF(200, 10), sf); textSize.Width += 20; if (RightToLeft == RightToLeft.No) { RectangleF buttonRect = new RectangleF(DEF_START_POS, 3, textSize.Width, 17); currentItem.StripRect = buttonRect; DEF_START_POS += (int)textSize.Width; } else { RectangleF buttonRect = new RectangleF(DEF_START_POS - textSize.Width + 1, 3, textSize.Width - 1, 17); currentItem.StripRect = buttonRect; DEF_START_POS -= (int)textSize.Width; } }
/// <summary> /// Assigns the specified item. /// </summary> /// <param name="item">The item.</param> public void Assign(ZeroitFameyeTabStripItem item) { Visible = item.Visible; Text = item.Text; CanClose = item.CanClose; Tag = item.Tag; }
/// <summary> /// Removes the specified item. /// </summary> /// <param name="item">The item.</param> public virtual void Remove(ZeroitFameyeTabStripItem item) { if (List.Contains(item)) { List.Remove(item); } }
/// <summary> /// Called when [insert complete]. /// </summary> /// <param name="index">The index.</param> /// <param name="item">The item.</param> protected override void OnInsertComplete(int index, object item) { ZeroitFameyeTabStripItem itm = item as ZeroitFameyeTabStripItem; itm.Changed += new EventHandler(OnItem_Changed); OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, item)); }
/// <summary> /// Handles the <see cref="E:Removing" /> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="ComponentEventArgs"/> instance containing the event data.</param> private void OnRemoving(object sender, ComponentEventArgs e) { IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); //Removing a button if (e.Component is ZeroitFameyeTabStripItem) { ZeroitFameyeTabStripItem itm = e.Component as ZeroitFameyeTabStripItem; if (Control.Items.Contains(itm)) { changeService.OnComponentChanging(Control, null); Control.RemoveTab(itm); changeService.OnComponentChanged(Control, null, null, null); return; } } if (e.Component is ZeroitFameyeTabStrip) { for (int i = Control.Items.Count - 1; i >= 0; i--) { ZeroitFameyeTabStripItem itm = Control.Items[i]; changeService.OnComponentChanging(Control, null); Control.RemoveTab(itm); host.DestroyComponent(itm); changeService.OnComponentChanged(Control, null, null, null); } } }
/// <summary> /// Called when [remove]. /// </summary> /// <param name="index">The index.</param> /// <param name="item">The item.</param> protected override void OnRemove(int index, object item) { base.OnRemove(index, item); ZeroitFameyeTabStripItem itm = item as ZeroitFameyeTabStripItem; itm.Changed -= new EventHandler(OnItem_Changed); OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Remove, item)); }
/// <summary> /// Inserts the specified index. /// </summary> /// <param name="index">The index.</param> /// <param name="item">The item.</param> public virtual void Insert(int index, ZeroitFameyeTabStripItem item) { if (Contains(item)) { return; } List.Insert(index, item); }
/// <summary> /// Adds the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns>System.Int32.</returns> public virtual int Add(ZeroitFameyeTabStripItem item) { int res = IndexOf(item); if (res == -1) { res = List.Add(item); } return(res); }
/// <summary> /// Add a <see cref="FATabStripItem" /> to this control. /// User can make the currently selected item or not. /// </summary> /// <param name="tabItem">The tab item.</param> /// <param name="autoSelect">if set to <c>true</c> [automatic select].</param> public void AddTab(ZeroitFameyeTabStripItem tabItem, bool autoSelect) { tabItem.Dock = DockStyle.Fill; Items.Add(tabItem); if ((autoSelect && tabItem.Visible) || (tabItem.Visible && Items.DrawnCount < 1)) { SelectedItem = tabItem; SelectItem(tabItem); } }
/// <summary> /// Sets the default selected. /// </summary> private void SetDefaultSelected() { if (selectedItem == null && Items.Count > 0) { SelectedItem = Items[0]; } for (int i = 0; i < Items.Count; i++) { ZeroitFameyeTabStripItem itm = Items[i]; itm.Dock = DockStyle.Fill; } }
/// <summary> /// Handles the <see cref="E:RemoveTabStrip" /> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void OnRemoveTabStrip(object sender, EventArgs e) { IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); DesignerTransaction transaction = host.CreateTransaction("Remove Button"); changeService.OnComponentChanging(Control, null); ZeroitFameyeTabStripItem itm = Control.Items[Control.Items.Count - 1]; Control.UnSelectItem(itm); Control.Items.Remove(itm); changeService.OnComponentChanged(Control, null, null, null); transaction.Commit(); }
/// <summary> /// Moves to. /// </summary> /// <param name="newIndex">The new index.</param> /// <param name="item">The item.</param> /// <returns>ZeroitFameyeTabStripItem.</returns> public virtual ZeroitFameyeTabStripItem MoveTo(int newIndex, ZeroitFameyeTabStripItem item) { int currentIndex = List.IndexOf(item); if (currentIndex >= 0) { RemoveAt(currentIndex); Insert(0, item); return(item); } return(null); }
/// <summary> /// Handles the <see cref="E:AddTabStrip" /> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void OnAddTabStrip(object sender, EventArgs e) { IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); DesignerTransaction transaction = host.CreateTransaction("Add TabStrip"); ZeroitFameyeTabStripItem itm = (ZeroitFameyeTabStripItem)host.CreateComponent(typeof(ZeroitFameyeTabStripItem)); changeService.OnComponentChanging(Control, null); Control.AddTab(itm); int indx = Control.Items.IndexOf(itm) + 1; itm.Title = "TabStrip Page " + indx.ToString(); Control.SelectItem(itm); changeService.OnComponentChanged(Control, null, null, null); transaction.Commit(); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.MouseDown" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button != MouseButtons.Left) { return; } HitTestResult result = HitTest(e.Location); if (result == HitTestResult.MenuGlyph) { HandledEventArgs args = new HandledEventArgs(false); OnMenuItemsLoading(args); if (!args.Handled) { OnMenuItemsLoad(EventArgs.Empty); } ShowMenu(); } else if (result == HitTestResult.CloseButton) { if (SelectedItem != null) { TabStripItemClosingEventArgs args = new TabStripItemClosingEventArgs(SelectedItem); OnTabStripItemClosing(args); if (!args.Cancel && SelectedItem.CanClose) { RemoveTab(SelectedItem); OnTabStripItemClosed(EventArgs.Empty); } } } else if (result == HitTestResult.TabItem) { ZeroitFameyeTabStripItem item = GetTabItemByPoint(e.Location); if (item != null) { SelectedItem = item; } } Invalidate(); }
/// <summary> /// WNDs the proc. /// </summary> /// <param name="msg">The MSG.</param> protected override void WndProc(ref Message msg) { if (msg.Msg == 0x201) { Point pt = Control.PointToClient(Cursor.Position); ZeroitFameyeTabStripItem itm = Control.GetTabItemByPoint(pt); if (itm != null) { Control.SelectedItem = itm; ArrayList selection = new ArrayList(); selection.Add(itm); ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService)); selectionService.SetSelectedComponents(selection); } } base.WndProc(ref msg); }
/// <summary> /// Assigns the specified collection. /// </summary> /// <param name="collection">The collection.</param> public virtual void Assign(FATabStripItemCollection collection) { BeginUpdate(); try { Clear(); for (int n = 0; n < collection.Count; n++) { ZeroitFameyeTabStripItem item = collection[n]; ZeroitFameyeTabStripItem newItem = new ZeroitFameyeTabStripItem(); newItem.Assign(item); Add(newItem); } } finally { EndUpdate(); } }
/// <summary> /// Allows the draw. /// </summary> /// <param name="item">The item.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> private bool AllowDraw(ZeroitFameyeTabStripItem item) { bool result = true; if (RightToLeft == RightToLeft.No) { if (item.StripRect.Right >= stripButtonRect.Width) { result = false; } } else { if (item.StripRect.Left <= stripButtonRect.Left) { return(false); } } return(result); }
/// <summary> /// Loads menu items based on <see cref="FATabStripItem" />s currently added /// to this control. /// </summary> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected virtual void OnMenuItemsLoad(EventArgs e) { menu.RightToLeft = RightToLeft; menu.Items.Clear(); for (int i = 0; i < Items.Count; i++) { ZeroitFameyeTabStripItem item = Items[i]; if (!item.Visible) { continue; } ToolStripMenuItem tItem = new ToolStripMenuItem(item.Title); tItem.Tag = item; tItem.Image = item.Image; menu.Items.Add(tItem); } OnMenuItemsLoaded(EventArgs.Empty); }
/// <summary> /// Handles the <see cref="E:CollectionChanged" /> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="CollectionChangeEventArgs"/> instance containing the event data.</param> private void OnCollectionChanged(object sender, CollectionChangeEventArgs e) { ZeroitFameyeTabStripItem itm = (ZeroitFameyeTabStripItem)e.Element; if (e.Action == CollectionChangeAction.Add) { Controls.Add(itm); OnTabStripItemChanged(new TabStripItemChangedEventArgs(itm, FATabStripItemChangeTypes.Added)); } else if (e.Action == CollectionChangeAction.Remove) { Controls.Remove(itm); OnTabStripItemChanged(new TabStripItemChangedEventArgs(itm, FATabStripItemChangeTypes.Removed)); } else { OnTabStripItemChanged(new TabStripItemChangedEventArgs(itm, FATabStripItemChangeTypes.Changed)); } UpdateLayout(); Invalidate(); }
/// <summary> /// Get a <see cref="FATabStripItem" /> at provided point. /// If no item was found, returns null value. /// </summary> /// <param name="pt">The pt.</param> /// <returns>ZeroitFameyeTabStripItem.</returns> public ZeroitFameyeTabStripItem GetTabItemByPoint(Point pt) { ZeroitFameyeTabStripItem item = null; bool found = false; for (int i = 0; i < Items.Count; i++) { ZeroitFameyeTabStripItem current = Items[i]; if (current.StripRect.Contains(pt) && current.Visible && current.IsDrawn) { item = current; found = true; } if (found) { break; } } return(item); }
/// <summary> /// Remove a <see cref="FATabStripItem" /> from this control. /// </summary> /// <param name="tabItem">The tab item.</param> public void RemoveTab(ZeroitFameyeTabStripItem tabItem) { int tabIndex = Items.IndexOf(tabItem); if (tabIndex >= 0) { UnSelectItem(tabItem); Items.Remove(tabItem); } if (Items.Count > 0) { if (RightToLeft == RightToLeft.No) { if (Items[tabIndex - 1] != null) { SelectedItem = Items[tabIndex - 1]; } else { SelectedItem = Items.FirstVisible; } } else { if (Items[tabIndex + 1] != null) { SelectedItem = Items[tabIndex + 1]; } else { SelectedItem = Items.LastVisible; } } } }
/// <summary> /// Add a <see cref="FATabStripItem" /> to this control without selecting it. /// </summary> /// <param name="tabItem">The tab item.</param> public void AddTab(ZeroitFameyeTabStripItem tabItem) { AddTab(tabItem, false); }
/// <summary> /// Called when [draw tab page]. /// </summary> /// <param name="g">The g.</param> /// <param name="currentItem">The current item.</param> private void OnDrawTabPage(Graphics g, ZeroitFameyeTabStripItem currentItem) { bool isFirstTab = Items.IndexOf(currentItem) == 0; Font currentFont = Font; if (currentItem == SelectedItem) { currentFont = new Font(Font, FontStyle.Bold); } SizeF textSize = g.MeasureString(currentItem.Title, currentFont, new SizeF(200, 10), sf); textSize.Width += 20; RectangleF buttonRect = currentItem.StripRect; GraphicsPath path = new GraphicsPath(); LinearGradientBrush brush; int mtop = 3; #region Draw Not Right-To-Left Tab if (RightToLeft == RightToLeft.No) { if (currentItem == SelectedItem || isFirstTab) { path.AddLine(buttonRect.Left - 10, buttonRect.Bottom - 1, buttonRect.Left + (buttonRect.Height / 2) - 4, mtop + 4); } else { path.AddLine(buttonRect.Left, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - (buttonRect.Height / 2) - 2); path.AddLine(buttonRect.Left, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Left + (buttonRect.Height / 2) - 4, mtop + 3); } path.AddLine(buttonRect.Left + (buttonRect.Height / 2) + 2, mtop, buttonRect.Right - 3, mtop); path.AddLine(buttonRect.Right, mtop + 2, buttonRect.Right, buttonRect.Bottom - 1); path.AddLine(buttonRect.Right - 4, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - 1); path.CloseFigure(); if (currentItem == SelectedItem) { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Window, LinearGradientMode.Vertical); } else { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical); } g.FillPath(brush, path); g.DrawPath(SystemPens.ControlDark, path); if (currentItem == SelectedItem) { g.DrawLine(new Pen(brush), buttonRect.Left - 9, buttonRect.Height + 2, buttonRect.Left + buttonRect.Width - 1, buttonRect.Height + 2); } PointF textLoc = new PointF(buttonRect.Left + buttonRect.Height - 4, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 3); RectangleF textRect = buttonRect; textRect.Location = textLoc; textRect.Width = buttonRect.Width - (textRect.Left - buttonRect.Left) - 4; textRect.Height = textSize.Height + currentFont.Size / 2; if (currentItem == SelectedItem) { //textRect.Y -= 2; g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } else { g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } } #endregion #region Draw Right-To-Left Tab if (RightToLeft == RightToLeft.Yes) { if (currentItem == SelectedItem || isFirstTab) { path.AddLine(buttonRect.Right + 10, buttonRect.Bottom - 1, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 4); } else { path.AddLine(buttonRect.Right, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 2); path.AddLine(buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 3); } path.AddLine(buttonRect.Right - (buttonRect.Height / 2) - 2, mtop, buttonRect.Left + 3, mtop); path.AddLine(buttonRect.Left, mtop + 2, buttonRect.Left, buttonRect.Bottom - 1); path.AddLine(buttonRect.Left + 4, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - 1); path.CloseFigure(); if (currentItem == SelectedItem) { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Window, LinearGradientMode.Vertical); } else { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical); } g.FillPath(brush, path); g.DrawPath(SystemPens.ControlDark, path); if (currentItem == SelectedItem) { g.DrawLine(new Pen(brush), buttonRect.Right + 9, buttonRect.Height + 2, buttonRect.Right - buttonRect.Width + 1, buttonRect.Height + 2); } PointF textLoc = new PointF(buttonRect.Left + 2, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2); RectangleF textRect = buttonRect; textRect.Location = textLoc; textRect.Width = buttonRect.Width - (textRect.Left - buttonRect.Left) - 10; textRect.Height = textSize.Height + currentFont.Size / 2; if (currentItem == SelectedItem) { textRect.Y -= 1; g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } else { g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } //g.FillRectangle(Brushes.Red, textRect); } #endregion currentItem.IsDrawn = true; }
/// <summary> /// Indexes the of. /// </summary> /// <param name="item">The item.</param> /// <returns>System.Int32.</returns> public virtual int IndexOf(ZeroitFameyeTabStripItem item) { return(List.IndexOf(item)); }
/// <summary> /// Handles the <see cref="E:MenuItemClicked" /> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="ToolStripItemClickedEventArgs"/> instance containing the event data.</param> private void OnMenuItemClicked(object sender, ToolStripItemClickedEventArgs e) { ZeroitFameyeTabStripItem clickedItem = (ZeroitFameyeTabStripItem)e.ClickedItem.Tag; SelectedItem = clickedItem; }
/// <summary> /// Determines whether [contains] [the specified item]. /// </summary> /// <param name="item">The item.</param> /// <returns><c>true</c> if [contains] [the specified item]; otherwise, <c>false</c>.</returns> public virtual bool Contains(ZeroitFameyeTabStripItem item) { return(List.Contains(item)); }
/// <summary> /// Initializes the designer with the specified component. /// </summary> /// <param name="component">The <see cref="T:System.ComponentModel.IComponent" /> to associate with the designer.</param> public override void Initialize(IComponent component) { base.Initialize(component); TabStrip = component as ZeroitFameyeTabStripItem; }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { SetDefaultSelected(); Rectangle borderRc = ClientRectangle; borderRc.Width--; borderRc.Height--; if (RightToLeft == RightToLeft.No) { DEF_START_POS = 10; } else { DEF_START_POS = stripButtonRect.Right; } e.Graphics.DrawRectangle(SystemPens.ControlDark, borderRc); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; #region Draw Pages for (int i = 0; i < Items.Count; i++) { ZeroitFameyeTabStripItem currentItem = Items[i]; if (!currentItem.Visible && !DesignMode) { continue; } OnCalcTabPage(e.Graphics, currentItem); currentItem.IsDrawn = false; if (!AllowDraw(currentItem)) { continue; } OnDrawTabPage(e.Graphics, currentItem); } #endregion #region Draw UnderPage Line if (RightToLeft == RightToLeft.No) { if (Items.DrawnCount == 0 || Items.VisibleCount == 0) { e.Graphics.DrawLine(SystemPens.ControlDark, new Point(0, DEF_HEADER_HEIGHT), new Point(ClientRectangle.Width, DEF_HEADER_HEIGHT)); } else if (SelectedItem != null && SelectedItem.IsDrawn) { Point end = new Point((int)SelectedItem.StripRect.Left - 9, DEF_HEADER_HEIGHT); e.Graphics.DrawLine(SystemPens.ControlDark, new Point(0, DEF_HEADER_HEIGHT), end); end.X += (int)SelectedItem.StripRect.Width + 10; e.Graphics.DrawLine(SystemPens.ControlDark, end, new Point(ClientRectangle.Width, DEF_HEADER_HEIGHT)); } } else { if (Items.DrawnCount == 0 || Items.VisibleCount == 0) { e.Graphics.DrawLine(SystemPens.ControlDark, new Point(0, DEF_HEADER_HEIGHT), new Point(ClientRectangle.Width, DEF_HEADER_HEIGHT)); } else if (SelectedItem != null && SelectedItem.IsDrawn) { Point end = new Point((int)SelectedItem.StripRect.Left, DEF_HEADER_HEIGHT); e.Graphics.DrawLine(SystemPens.ControlDark, new Point(0, DEF_HEADER_HEIGHT), end); end.X += (int)SelectedItem.StripRect.Width + 20; e.Graphics.DrawLine(SystemPens.ControlDark, end, new Point(ClientRectangle.Width, DEF_HEADER_HEIGHT)); } } #endregion #region Draw Menu and Close Glyphs if (AlwaysShowMenuGlyph || Items.DrawnCount > Items.VisibleCount) { menuGlyph.DrawGlyph(e.Graphics); } if (AlwaysShowClose || (SelectedItem != null && SelectedItem.CanClose)) { closeButton.DrawCross(e.Graphics); } #endregion }
/// <summary> /// Uns the select item. /// </summary> /// <param name="tabItem">The tab item.</param> internal void UnSelectItem(ZeroitFameyeTabStripItem tabItem) { //tabItem.Visible = false; tabItem.Selected = false; }
/// <summary> /// Selects the item. /// </summary> /// <param name="tabItem">The tab item.</param> internal void SelectItem(ZeroitFameyeTabStripItem tabItem) { tabItem.Dock = DockStyle.Fill; tabItem.Visible = true; tabItem.Selected = true; }