public ControlContainerTabs Rebuild()
        {
            ControlContainerTabs tabControl = new ControlContainerTabs
            {
                BorderStyle           = System.Windows.Forms.BorderStyle.FixedSingle,
                Dock                  = System.Windows.Forms.DockStyle.Fill,
                Current               = null,
                TabIndex              = 0,
                ShowHeaderWhenOnlyOne = ShowHeaderWhenOnlyOne
            };

            foreach (string name in ChildrenName)
            {
                Type type = FactoryOfTaxonControl.TaxonUserControlTypeFromName(name);
                if (type == null)
                {
                    continue;
                }
                object o = type.GetConstructor(new Type[] { }).Invoke(new object[] { });
                if (!(o is Controls.TaxonControl))
                {
                    continue;
                }
                tabControl.Add(o as Controls.TaxonControl);
            }

            if (CurrentIndex >= 0 && CurrentIndex < tabControl.Children.Count)
            {
                tabControl.Current = tabControl.Children[CurrentIndex];
            }

            return(tabControl);
        }
Example #2
0
        //-------------------------------------------------------------------
        void PaintTabs(Graphics G)
        {
            // Paint Header
            if (Children.Count == 0)
            {
                return;
            }
            if (Children.Count == 1 && !ShowHeaderWhenOnlyOne)
            {
                return;
            }

            _HeaderVisible = true;

            int indexCurrent = Children.IndexOf(Current);

            if (indexCurrent == -1)
            {
                return;
            }

            int[] wChild = new int[Children.Count];
            int   wTotal = 0;

            for (int i = 0; i < Children.Count; i++)
            {
                TaxonControlInfo info = FactoryOfTaxonControl.TaxonControlInfoFromType(Children[i].GetType());
                info.CurrentTaxonControl = Children[i];

                int w = (int)G.MeasureString(info.DisplayName, Font).Width + 1;
                w += 2 * Theme.Current.TabHeader_Margin;
                w += Theme.Current.TabHeader_IconSize + Theme.Current.TabHeader_GapBetweenIconAndText;

                wChild[i] = w;
                wTotal   += w;
            }

            int[] X = new int[Children.Count + 1];
            int   x = 0;

            if (wTotal < Width)
            {
                for (int i = 0; i < Children.Count; i++)
                {
                    X[i] = x;
                    x   += wChild[i];
                }
                X[Children.Count] = x;
            }
            else if (Children.Count == 1)
            {
                X[1] = Width;
            }
            else
            {
                int[] newW = new int[Children.Count];
                newW[indexCurrent] = wChild[indexCurrent];
                int wLeft       = Width - wChild[indexCurrent];
                int wLeftTab    = (Children.Count - 1);
                int wLeftPerTab = wLeft / wLeftTab;

                if (wLeftPerTab < 24)
                {
                    if (indexCurrent > 0)
                    {
                        _PrevButtonVisible = true;
                        _PrevButtonRect    = new Rectangle(0, (Theme.Current.TabHeader_Height - 16) / 2, 16, 16);
                        x = 20;
                    }
                    newW[indexCurrent] = Width - x;
                    if (indexCurrent < Children.Count - 1)
                    {
                        _NextButtonVisible  = true;
                        _NextButtonRect     = new Rectangle(Width - 16, (Theme.Current.TabHeader_Height - 16) / 2, 16, 16);
                        newW[indexCurrent] -= 20;
                    }
                }
                else
                {
                    bool ended = false;
                    while (!ended)
                    {
                        ended = true;
                        for (int i = 0; i < Children.Count; i++)
                        {
                            if (newW[i] == 0 && wChild[i] < wLeftPerTab)
                            {
                                newW[i] = wChild[i];
                                wLeft  -= wChild[i];
                                wLeftTab--;
                                wLeftPerTab = wLeft / wLeftTab;
                                ended       = false;
                            }
                        }
                    }

                    for (int i = 0; i < Children.Count; i++)
                    {
                        if (newW[i] == 0)
                        {
                            newW[i] = wLeftPerTab;
                        }
                    }
                }

                for (int i = 0; i < Children.Count; i++)
                {
                    X[i] = x;
                    x   += newW[i];
                }
                X[Children.Count] = x;
            }

            _ChildrenRect.Clear();

            for (int i = 0; i < Children.Count; i++)
            {
                Rectangle R = Rectangle.FromLTRB(X[i], 0, X[i + 1], Theme.Current.TabHeader_Height);
                _ChildrenRect.Add(R);
                if (R.Width == 0)
                {
                    continue;
                }
                if (indexCurrent == i)
                {
                    continue;
                }

                TaxonControlInfo info = FactoryOfTaxonControl.TaxonControlInfoFromType(Children[i].GetType());
                Draw.IconAndText(G, R, info.DisplayName, Font, info.Icon, Theme.Current.TabHeaderParams);
            }

            if (_PrevButtonVisible)
            {
                ControlPaint.DrawScrollButton(G, _PrevButtonRect, ScrollButton.Left, ButtonState.Normal);
            }
            if (_NextButtonVisible)
            {
                ControlPaint.DrawScrollButton(G, _NextButtonRect, ScrollButton.Right, ButtonState.Normal);
            }

            // draw at last selected tab
            {
                TaxonControlInfo info = FactoryOfTaxonControl.TaxonControlInfoFromType(Children[indexCurrent].GetType());
                Rectangle        R    = _ChildrenRect[indexCurrent];
                G.FillRectangle(Theme.Current.TabHeader_SelectedBackground, R);
                if (R.Right < ClientRectangle.Right)
                {
                    G.DrawLine(Theme.Current.TabHeader_DarkShadow, R.Right, R.Top, R.Right, R.Bottom - 2);
                }
                if (R.Left > 0)
                {
                    G.DrawLine(Theme.Current.TabHeader_LightShadow, R.Left, R.Bottom, R.Left, R.Top);
                }
                G.DrawLine(Theme.Current.TabHeader_LightShadow, R.Left, R.Top, R.Right, R.Top);
                Draw.IconAndText(G, R, info.DisplayName, Font, info.Icon, Theme.Current.SelectedTabHeaderParams);
            }
        }