/// <summary>
        /// Used to change the new tab page to a custom MaterialTabPage
        /// </summary>
        /// <param name="e"></param>
        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);

            //A try event to detect if the tab page is a material tab page
            try
            {
                //If failed to convert to a MaterialTabPage, this is a refrence of TabPage
                MaterialTabPage tabPage = (MaterialTabPage)e.Control;
            }
            catch
            {
                //Initializing both TabPage and the new MaterialTabPage
                TabPage         tabPage    = (TabPage)e.Control;
                MaterialTabPage newTabPage = new MaterialTabPage();

                //Setting custom vars to the NewTabPage
                newTabPage.Text      = tabPage.Text;
                newTabPage.BackColor = tabPage.BackColor;

                //Removing the old one and adding the new tab page
                this.TabPages.Remove(tabPage);
                this.TabPages.Add(newTabPage);
            }
        }
Beispiel #2
0
        private void PaintTab(Rectangle TabRectangle, MaterialTabPage tabPage, Graphics g, Color BackColor, Color BorderColor, Color TopBorderColor, Status tabStatus)
        {
            int tabIndex = basedTabControl.TabPages.IndexOf(tabPage);

            Color tabTextColor = Color.White;

            //Draw background of the tab
            g.FillRectangle(new SolidBrush(BackColor), TabRectangle);

            //Draw borders of the tab
            if ((tabIndex + 1) != basedTabControl.TabPages.Count)
            {
                ControlPaint.DrawBorder(g, TabRectangle, BackColor, 1, ButtonBorderStyle.Solid,
                                        BackColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid,
                                        BackColor, 1, ButtonBorderStyle.Solid);
            }

            if (tabStatus == Status.Selected)
            {
                tabTextColor = Color.Black;
            }

            int drawIcon = 0;

            if (tabPage.icon != null)
            {
                int       iconSize      = 22; drawIcon = 22;
                Point     IconLocation  = new Point(TabRectangle.X + 4, TabRectangle.Y + 5);
                Rectangle iconRectangle = new Rectangle(IconLocation, new Size(iconSize, iconSize));
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.DrawImage(tabPage.icon, iconRectangle);
                g.InterpolationMode = InterpolationMode.Default;
            }

            string tabText  = tabPage.Text;
            int    maxChars = _maxChars;

            if (_limitStringLength)
            {
                if (_showCloseButt == true)
                {
                    maxChars = _maxCharswithClose;
                }

                if (tabText.Length > maxChars)
                {
                    tabText = tabText.Substring(0, Math.Min(tabText.Length, maxChars)) + "...";
                }
            }

            //Draws the text of the tab
            StringFormat sf          = new StringFormat(); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center;
            Rectangle    tabTextRect = new Rectangle(TabRectangle.X + 6 + drawIcon, TabRectangle.Y, TabRectangle.Width - 6, TabRectangle.Height);

            g.DrawString(tabText, new Font("Segoe UI", 11), new SolidBrush(tabTextColor), tabTextRect, sf);
        }
        protected override object CreateInstance(Type itemType)
        {
            MaterialTabPage tabPage = (MaterialTabPage)itemType.Assembly.CreateInstance(itemType.FullName);

            IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            host.Container.Add(tabPage);
            //this.Context.Container.Add(tabPage);

            tabPage.Text = tabPage.Name;
            return(tabPage);
        }
Beispiel #4
0
        private void PaintTab(Rectangle TabRectangle, Graphics g)
        {
            Status tabStatus = Status.Default;

            MaterialTabPage tabPage = GetTabByPoint(TabRectangle);

            if (basedTabControl.SelectedTab == tabPage)
            {
                tabStatus = Status.Selected;
            }
            else if (TabRectangle.Contains(this.PointToClient(MousePosition)))
            {
                tabStatus = Status.MouseOver;
            }

            Color tabColor      = Color.Red;
            Color p_TopBarColor = Color.Red;
            Color fontColor     = Color.Red;

            if (tabStatus == Status.Default)
            {
                PaintTab(TabRectangle, tabPage, g, tabBackColor, tabBorderColor, topBorderColor, tabStatus);
                tabColor = tabBackColor; p_TopBarColor = topBorderColor; fontColor = Color.White;
            }
            else if (tabStatus == Status.MouseOver)
            {
                PaintTab(TabRectangle, tabPage, g, h_tabBackColor, h_tabBorderColor, h_topBorderColor, tabStatus);
                tabColor = h_tabBackColor; p_TopBarColor = h_topBorderColor; fontColor = Color.White;
            }
            else if (tabStatus == Status.Selected)
            {
                PaintTab(TabRectangle, tabPage, g, s_tabBackColor, s_TabBorderColor, s_topBorderColor, tabStatus);

                tabColor = s_tabBackColor; p_TopBarColor = s_topBorderColor; fontColor = Color.Black;
            }

            if (_showCloseButt)
            {
                int intY = TabRectangle.Height; Rectangle buttonRectangle = new Rectangle(new Point(TabRectangle.X + TabRectangle.Width - intY - 1, 3), new Size(intY, intY - 3));
                if (buttonRectangle.Contains(this.PointToClient(MousePosition)))
                {
                    DrawTabCloseButton(g, buttonRectangle, Color.FromArgb(255, 90, 90), Color.FromArgb(0, 0, 0));
                }
                else
                {
                    DrawTabCloseButton(g, buttonRectangle, tabColor, fontColor);
                }
            }

            Rectangle drawRect = new Rectangle(new Point(TabRectangle.X, TabRectangle.Y), new Size(TabRectangle.Width, 3));

            DrawTopBar(g, drawRect, p_TopBarColor);
        }
Beispiel #5
0
        private MaterialTabPage GetTabByPoint(Rectangle rect)
        {
            MaterialTabPage returnTab = null;

            for (int i = 0; i < tabRectangles.Count; i++)
            {
                if (tabRectangles[i].Contains(rect))
                {
                    returnTab = (MaterialTabPage)basedTabControl.TabPages[i];
                }
            }
            return(returnTab);
        }
Beispiel #6
0
        private MaterialTabPage GetTabByPoint(Point point)
        {
            MaterialTabPage returnTabPage = null;

            foreach (Rectangle rect in tabRectangles)
            {
                if (rect.Contains(this.PointToClient(point)))
                {
                    returnTabPage = (MaterialTabPage)basedTabControl.TabPages[tabRectangles.IndexOf(rect)];
                }
            }
            return(returnTabPage);
        }
Beispiel #7
0
        private MaterialTabPage GetTabByPoint(Point pt, bool isDragnDrop)
        {
            MaterialTabPage tp = null; Point pt1 = this.PointToClient(pt);

            tabRectangles = GetTabRectangles();
            for (int i = 0; i < this.basedTabControl.TabPages.Count; i++)
            {
                if (tabRectangles[i].Contains(pt1))
                {
                    tp = (MaterialTabPage)this.basedTabControl.TabPages[i];
                    break;
                }
            }

            return(tp);
        }
Beispiel #8
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            MaterialTabPage tp = GetTabByPoint(MousePosition);

            if (tp != null)
            {
                this.tabRectangles = this.GetTabRectangles();
                int tabIndex = this.basedTabControl.TabPages.IndexOf(tp); Rectangle TabRectangle = this.tabRectangles[tabIndex];
                int intY = TabRectangle.Height; Rectangle closeButtonRect = new Rectangle(new Point(TabRectangle.X + TabRectangle.Width - intY - 1, 3), new Size(intY, intY - 3));

                this.basedTabControl.SelectedTab = tp;

                if (!closeButtonRect.Contains(this.PointToClient(MousePosition)))
                {
                    this.DoDragDrop(tp, DragDropEffects.All);
                }
            }

            base.OnMouseDown(e);
        }
Beispiel #9
0
        /// <summary>
        /// Occures when there is a Drag'n'Drop event over the control
        /// </summary>
        protected override void OnDragOver(DragEventArgs drgevent)
        {
            //Triggers base event
            base.OnDragOver(drgevent);

            //Get position of the Drag'n'Drop
            Point pt = new Point(drgevent.X, drgevent.Y);

            //Get the hover tab from TabPoint
            MaterialTabPage hoverTab = GetTabByPoint(pt, true);

            //Checks if the hover tab is is null
            if (hoverTab != null)
            {
                preDraggedTab = hoverTab;
                //Set drag events
                drgevent.Effect = DragDropEffects.Move;
                var dragTab = drgevent.Data.GetData(typeof(MaterialTabPage));

                //Setting index for Item Drag and Drop Location
                int item_drag_index     = FindIndex((MaterialTabPage)dragTab);
                int drop_Location_Index = FindIndex(hoverTab);

                //Setting the PreDraggedTab
                preDraggedTab = (MaterialTabPage)dragTab;

                //Making sure the index is not equal to the origional index
                if (item_drag_index != drop_Location_Index)
                {
                    //Initializing the Array
                    ArrayList pages = new ArrayList();

                    //For each tab page
                    for (int i = 0; i < this.basedTabControl.TabPages.Count; i++)
                    {
                        if (i != item_drag_index)
                        {
                            pages.Add(this.basedTabControl.TabPages[i]);
                        }
                    }

                    //Insert page into the Drop iNDEX
                    pages.Insert(drop_Location_Index, (MaterialTabPage)dragTab);

                    //Clearing TabPages from the tab control
                    this.basedTabControl.TabPages.Clear();

                    //Adding tab pages to the BasedTabControl
                    this.basedTabControl.TabPages.AddRange((MaterialTabPage[])pages.ToArray(typeof(MaterialTabPage)));

                    //Selecting the DragTab
                    this.basedTabControl.SelectedTab = (MaterialTabPage)dragTab;

                    //Triggers event
                    TabDragComplete?.Invoke(this, new EventArgs());
                }
            }
            else
            {
                //Setting DragDropEffects to none
                drgevent.Effect = DragDropEffects.None;
            }
        }
Beispiel #10
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            Console.WriteLine(1);
            MaterialTabPage tp = GetTabByPoint(MousePosition);
            MaterialTabPage currentSelectedTab = (MaterialTabPage)basedTabControl.SelectedTab;

            Console.WriteLine(2);
            Rectangle leftArrow     = GetLeftRectangle();
            Rectangle rightArrow    = GetRightRectangle();
            Rectangle plusRectangle = GetPlusRectangle();

            Console.WriteLine(3);
            bool continueMethod = true;

            Console.WriteLine(4);
            if (_showNewTabButton)
            {
                if (plusRectangle.Contains(this.PointToClient(MousePosition)))
                {
                    MaterialTabPage NewTab = new MaterialTabPage();

                    NewTab.Text = "New Tab";

                    this.basedTabControl.TabPages.Add(NewTab);
                    this.basedTabControl.SelectedTab = NewTab;

                    continueMethod = false;
                    NewTabButtonClick?.Invoke(this, new NewTabButtonClickedEventArgs {
                        NewTabPage = NewTab
                    });
                }
            }
            Console.WriteLine(5);
            if (tp != null && continueMethod)
            {
                Console.WriteLine(6);
                this.tabRectangles = this.GetTabRectangles();
                int tabIndex = this.basedTabControl.TabPages.IndexOf(tp); Rectangle TabRectangle = this.tabRectangles[tabIndex];
                int intY = TabRectangle.Height; Rectangle closeButtonRect = new Rectangle(new Point(TabRectangle.X + TabRectangle.Width - intY - 1, 3), new Size(intY, intY - 3));

                if (leftArrow.Contains(this.PointToClient(MousePosition)))
                {
                    ScrollLeft();
                }
                else if (rightArrow.Contains(this.PointToClient(MousePosition)))
                {
                    ScrollRight();
                }
                else if (closeButtonRect.Contains(this.PointToClient(MousePosition)))
                {
                    Console.WriteLine(7);
                    if (this.basedTabControl.SelectedTab == tp && this.basedTabControl.TabPages.Count != 1)
                    {
                        if (this.basedTabControl.TabPages.Count - 1 == tabIndex)
                        {
                            this.basedTabControl.SelectedTab = this.basedTabControl.TabPages[tabIndex - 1];
                        }
                        else
                        {
                            this.basedTabControl.SelectedTab = this.basedTabControl.TabPages[tabIndex + 1];
                        }
                    }
                    else
                    {
                        basedTabControl.SelectedTab = currentSelectedTab;
                    }

                    this.basedTabControl.TabPages.Remove(tp);
                    tp.Dispose();
                }
            }
        }