Ejemplo n.º 1
0
        internal void DrawTab(Graphics g, TabPage tabPage, int nIndex)
        {
            Rectangle  recBounds   = this.GetTabRect(nIndex);
            RectangleF tabTextArea = (RectangleF)this.GetTabRect(nIndex);

            //debug --> to be fixed
            if (recBounds.Width == 0)
            {
                recBounds.Width = 50;
            }
            if (tabTextArea.Width == 0)
            {
                tabTextArea.Width = 50;
            }
            if (recBounds.Height == 0)
            {
                recBounds.Width = 22;
            }
            if (tabTextArea.Height == 0)
            {
                tabTextArea.Width = 22;
            }


            bool bSelected = (this.SelectedIndex == nIndex);
            bool bHot      = false;

            if (tabPage.Tag != null)
            {
                bHot = (bool)tabPage.Tag;
            }

            //for buttons appearance
            if (this.Appearance != TabAppearance.Normal)
            {
                _cornerLeftWidth  = 0;
                _cornerRightWidth = 0;
                _cornerWidth      = 0;
                this.Alignment    = TabAlignment.Top;
            }

            //Tab Hedaer Status
            DrawingMethods.TabHeaderStatus Status = DrawingMethods.TabHeaderStatus.Normal;
            if (_preserveTabColor)
            {
                Status = DrawingMethods.TabHeaderStatus.NormalPreserve;
            }
            if (bHot)
            {
                Status = DrawingMethods.TabHeaderStatus.Hot;
            }

            //bool bHotselected = false;

            if ((bSelected) && (!bHot))
            {
                Status = DrawingMethods.TabHeaderStatus.Selected;
            }
            else if ((bSelected) && (bHot))
            {
                Status = DrawingMethods.TabHeaderStatus.HotSelected;
                //bHotselected = true;
            }

            //Selected tab has to be highter
            if (!_allowSelectedTabHigh)
            {
                _allowSelectedTabHighSize = 0;
            }
            else
            {
                _allowSelectedTabHighSize = 1;
            }

            //Create tab Header Points (Sqared)
            Point[] pt = DrawingMethods.GetTabSquaredPoints(recBounds, _cornerWidth, Alignment, _cornerLeftWidth, _cornerRightWidth, this.Appearance, Status, _allowSelectedTabHighSize, false);

            //----------------------------
            // fill this tab with background color
            Brush br = new SolidBrush(tabPage.BackColor);

            //Font for header
            Font fnt = Font;

            switch (Status)
            {
            case DrawingMethods.TabHeaderStatus.Selected:
                DrawingMethods.DrawTabHeader(g, pt, recBounds, _tabColorSelectedLight, _tabColorSelectedDark, tabPage.BackColor, 90, Alignment, _useExtendedLayout, Status, false);
                fnt = new Font(Font.FontFamily, Font.SizeInPoints, FontStyle.Bold);
                br  = new SolidBrush(_tabForeColor);
                break;

            case DrawingMethods.TabHeaderStatus.HotSelected:
                DrawingMethods.DrawTabHeader(g, pt, recBounds, _tabColorSelectedLight, DrawingMethods.GetLighterColor(_tabColorSelectedDark), tabPage.BackColor, 90, Alignment, _useExtendedLayout, Status, false);
                fnt = new Font(Font.FontFamily, Font.SizeInPoints, FontStyle.Bold);
                br  = new SolidBrush(_tabHotForeColor);
                break;

            case DrawingMethods.TabHeaderStatus.Hot:
                DrawingMethods.DrawTabHeader(g, pt, recBounds, _tabColorHotLight, _tabColorHotDark, _tabColorHotLight, 90, Alignment, _useExtendedLayout, Status, false);
                br = new SolidBrush(_tabHotForeColor);
                break;

            case DrawingMethods.TabHeaderStatus.Normal:
                DrawingMethods.DrawTabHeader(g, pt, recBounds, _tabColorDefaultLight, _tabColorDefaultDark, _tabColorDefaultLight, 90, Alignment, _useExtendedLayout, Status, false);
                br = new SolidBrush(_tabForeColor);
                break;

            case DrawingMethods.TabHeaderStatus.NormalPreserve:
                DrawingMethods.DrawTabHeader(g, pt, recBounds, DrawingMethods.GetSystemLighterColor(tabPage.BackColor), DrawingMethods.GetDarkerColor(tabPage.BackColor), tabPage.BackColor, 90, Alignment, _useExtendedLayout, Status, true);
                br = new SolidBrush(_tabForeColor);
                break;
            }

            //----------------------------

            //----------------------------
            // draw border
            //g.DrawRectangle(SystemPens.ControlDark, recBounds);
            g.DrawPolygon(new Pen(_borderColor, _borderWidth), pt);
            //----------------------------

            if (((Status == DrawingMethods.TabHeaderStatus.Selected) || (Status == DrawingMethods.TabHeaderStatus.HotSelected)) && (this.Appearance == TabAppearance.Normal))
            {
                //----------------------------
                // clear bottom lines
                Pen pen = new Pen(tabPage.BackColor);

                DrawingMethods.ClearTabSelectedBottomLine(g, recBounds, pen, this.Alignment);

                pen.Dispose();
                //----------------------------
            }
            //----------------------------

            //----------------------------
            // draw tab's icon
            if ((tabPage.ImageIndex >= 0) && (ImageList != null) && (ImageList.Images[tabPage.ImageIndex] != null))
            {
                int nLeftMargin  = 8;
                int nRightMargin = 2;

                Image img = ImageList.Images[tabPage.ImageIndex];

                Rectangle rimage = new Rectangle(recBounds.X + nLeftMargin, recBounds.Y + 1, img.Width, img.Height);

                // adjust rectangles
                float nAdj = (float)(nLeftMargin + img.Width + nRightMargin);

                // adjust rectangles
                if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
                {
                    nAdj = (float)(nLeftMargin + img.Width + nRightMargin);

                    rimage.Y          += (recBounds.Height - img.Height) / 2;
                    tabTextArea.X     += nAdj;
                    tabTextArea.Width -= nAdj;
                }
                else
                {
                    if (_useExtendedLayout == false)
                    {
                        img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        rimage.X -= 5;
                    }
                    //rimage.X += (recBounds.Width - img.Width) / 2;

                    rimage.Y += 3;

                    nAdj                = (float)(10 + img.Height);
                    tabTextArea.Y      += img.Height;
                    tabTextArea.Height -= img.Height;
                }

                // draw icon
                g.DrawImage(img, rimage);
            }
            //no image
            else
            {
                if (_useExtendedLayout == true)
                {
                    tabTextArea.Y      += 16;
                    tabTextArea.Height -= 16;
                }
            }
            //----------------------------

            //----------------------------
            // draw string
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;

            //rtl
            if (this.RightToLeft == RightToLeft.Yes)
            {
                stringFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
            }

            //Disabled
            if (!this.Enabled)
            {
                br = new SolidBrush(SystemColors.GrayText);
            }

            if (this.Alignment == TabAlignment.Right || this.Alignment == TabAlignment.Left)
            {
                //not ExtendedLayout
                if (_useExtendedLayout == false)
                {
                    stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
                    tabTextArea.Offset(-3, -5);
                }
                else
                //Extended Layout
                {
                    tabTextArea.Height = tabTextArea.Height + 8;
                    tabTextArea.Offset(4, -12);
                    stringFormat.FormatFlags = StringFormatFlags.NoWrap;
                    stringFormat.Trimming    = StringTrimming.EllipsisCharacter;
                }
            }
            else
            {
                tabTextArea.Offset(-5, 0);
            }

            //use AntiAlias
            if (Utility.IsVista())
            {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            }
            else
            {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
            }

            g.DrawString(tabPage.Text, fnt, br, tabTextArea, stringFormat);
            //----------------------------

            br.Dispose();
        }