Example #1
0
        /// <summary>Draws the headers border.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        /// <param name="tabPage">The tab page to draw.</param>
        private static void DrawBorderHeader(Graphics graphics, VisualTabPage tabPage)
        {
            if (!tabPage.Border.Visible)
            {
                return;
            }

            GraphicsPath _borderGraphicsPath = new GraphicsPath();

            _borderGraphicsPath.AddRectangle(tabPage.Rectangle);
            Pen _borderPen = new Pen(tabPage.Border.Color, tabPage.Border.Thickness);

            graphics.DrawPath(_borderPen, _borderGraphicsPath);
        }
Example #2
0
        /// <summary>Draws the tab header content.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        /// <param name="tabPage">The tab page.</param>
        /// <param name="selected">The selected toggle.</param>
        private static void DrawContentHeader(Graphics graphics, VisualTabPage tabPage, bool selected)
        {
            Rectangle _imageRectangle       = new Rectangle(tabPage.Rectangle.X + tabPage.Border.Thickness + 1, (tabPage.Rectangle.Y + (tabPage.Rectangle.Height / 2)) - (tabPage.ImageSize.Height / 2), tabPage.ImageSize.Width, tabPage.ImageSize.Height);
            Rectangle _imageCenterRectangle = new Rectangle((tabPage.Rectangle.X + (tabPage.Rectangle.Width / 2)) - (tabPage.ImageSize.Width / 2), (tabPage.Rectangle.Y + (tabPage.Rectangle.Height / 2)) - (tabPage.ImageSize.Height / 2), tabPage.ImageSize.Width, tabPage.ImageSize.Height);

            StringFormat _tabStringFormat = new StringFormat {
                Alignment = tabPage.TextAlignment, LineAlignment = tabPage.TextLineAlignment
            };

            Size  _textSize  = StringUtil.MeasureText(tabPage.Text, tabPage.Font, graphics);
            Color _foreColor = selected ? tabPage.TextSelected : tabPage.ForeColor;

            switch (tabPage.TextImageRelation)
            {
            case VisualTabPage.TextImageRelations.ImageBeforeText:
            {
                if (tabPage.Image != null)
                {
                    graphics.DrawImage(tabPage.Image, _imageRectangle);
                }

                graphics.DrawString(tabPage.Text, tabPage.Font, new SolidBrush(_foreColor), new Rectangle(_imageRectangle.Right + 1, (tabPage.Rectangle.Y + (tabPage.Rectangle.Height / 2)) - (_textSize.Height / 2), tabPage.Rectangle.Width, tabPage.Rectangle.Height));

                break;
            }

            case VisualTabPage.TextImageRelations.Image:
            {
                if (tabPage.Image != null)
                {
                    graphics.DrawImage(tabPage.Image, _imageCenterRectangle);
                }

                break;
            }

            case VisualTabPage.TextImageRelations.Text:
            {
                graphics.DrawString(tabPage.Text, tabPage.Font, new SolidBrush(_foreColor), tabPage.Rectangle, _tabStringFormat);
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }
        }
Example #3
0
        private void OnAddPage(object sender, EventArgs e)
        {
            VisualTabControl _parentalControl = (VisualTabControl)Control;
            Control.ControlCollection _controlCollection = _parentalControl.Controls;

            RaiseComponentChanging(TypeDescriptor.GetProperties(_parentalControl)["TabPages"]);

            VisualTabPage _tabPage = (VisualTabPage)DesignerHost.CreateComponent(typeof(VisualTabPage));
            _tabPage.Text = _tabPage.Name;
            _parentalControl.TabPages.Add(_tabPage);

            RaiseComponentChanged(TypeDescriptor.GetProperties(_parentalControl)["TabPages"], _controlCollection, _parentalControl.TabPages);
            _parentalControl.SelectedTab = _tabPage;

            SetVerbs();
        }
Example #4
0
        /// <summary>Draws the selector.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        /// <param name="selectorType">The selector Type.</param>
        private void DrawSelector(Graphics graphics, SelectorTypes selectorType)
        {
            if (_selectorVisible)
            {
                try
                {
                    for (var tabIndex = 0; tabIndex <= TabCount - 1; tabIndex++)
                    {
                        VisualTabPage _tabPage = (VisualTabPage)TabPages[tabIndex];
                        _tabPage.Rectangle = GetStyledTabRectangle(tabIndex);

                        if (tabIndex == SelectedIndex)
                        {
                            switch (selectorType)
                            {
                            case SelectorTypes.Arrow:
                            {
                                DrawSelectorArrow(graphics, _tabPage.Rectangle);
                                break;
                            }

                            case SelectorTypes.Line:
                            {
                                DrawSelectorLine(graphics, _tabPage.Rectangle);
                                break;
                            }

                            default:
                            {
                                throw new ArgumentOutOfRangeException(nameof(selectorType), selectorType, null);
                            }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.WriteDebug(e);
                }
            }
        }
Example #5
0
        /// <summary>Draws the tab pages.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        private void DrawTabPages(Graphics graphics)
        {
            try
            {
                for (var tabIndex = 0; tabIndex <= TabCount - 1; tabIndex++)
                {
                    VisualTabPage _tabPage = (VisualTabPage)TabPages[tabIndex];
                    _tabPage.Rectangle = GetStyledTabRectangle(tabIndex);

                    if (tabIndex == SelectedIndex)
                    {
                        // Selected tab header
                        DrawBackgroundHeader(graphics, _tabPage, true);
                        DrawBorderHeader(graphics, _tabPage);
                        DrawContentHeader(graphics, _tabPage, true);
                    }
                    else
                    {
                        // Unselected tab header
                        DrawBackgroundHeader(graphics, _tabPage, false);

                        if ((_mouseState == MouseStates.Hover) && _tabPage.Rectangle.Contains(_mouseLocation))
                        {
                            graphics.FillRectangle(new SolidBrush(_tabPage.TabHover), _tabPage.Rectangle);
                        }

                        DrawBorderHeader(graphics, _tabPage);
                        DrawContentHeader(graphics, _tabPage, false);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.WriteDebug(e);
            }
        }
        private void OnInsertPage(object sender, EventArgs e)
        {
            VisualTabControl _parentalControl = (VisualTabControl)Control;

            Control.ControlCollection _controlCollection = _parentalControl.Controls;
            int _index = _parentalControl.SelectedIndex;

            RaiseComponentChanging(TypeDescriptor.GetProperties(_parentalControl)["TabPages"]);

            VisualTabPage _tabPage = (VisualTabPage)DesignerHost.CreateComponent(typeof(VisualTabPage));

            _tabPage.Text = _tabPage.Name;

            var _tabPageCollection = new VisualTabPage[_parentalControl.TabCount];

            // Starting at our Insert Position, store and remove all the tab pages.
            for (int i = _index; i <= _tabPageCollection.Length - 1; i++)
            {
                _tabPageCollection[i] = (VisualTabPage)_parentalControl.TabPages[_index];
                _parentalControl.TabPages.Remove(_parentalControl.TabPages[_index]);
            }

            // add the tab page to be inserted.
            _parentalControl.TabPages.Add(_tabPage);

            // then re-add the original tab pages.
            for (int i = _index; i <= _tabPageCollection.Length - 1; i++)
            {
                _parentalControl.TabPages.Add(_tabPageCollection[i]);
            }

            RaiseComponentChanged(TypeDescriptor.GetProperties(_parentalControl)["TabPages"], _controlCollection, _parentalControl.TabPages);
            _parentalControl.SelectedTab = _tabPage;

            SetVerbs();
        }