예제 #1
0
        /// <summary>
        /// Draws a single tab.
        /// </summary>
        /// <param name="g">A <see cref="T:System.Drawing.Graphics"/> object used to draw the tab control.</param>
        /// <param name="index">An index of the tab being drawn.</param>
        /// <param name="tabRect">A <see cref="T:System.Drawing.Rectangle"/> object specifying tab's bounds.</param>
        /// <param name="rend">A <see cref="T:System.Windows.Forms.VisualStyles.VisualStyleRenderer"/> object for rendering the tab.</param>
        private void DrawTabItem(Graphics g, int index, Rectangle tabRect, VisualStyleRenderer rend)
        {
            //if the scroller is visible and the tab is fully placed under it, we don't need to draw such tab
            if (fUpDown.X > 0 && tabRect.X >= fUpDown.X)
            {
                return;
            }

            bool tabSelected = rend.State == (int)TabItemState.Selected;

            // We will draw our tab on a bitmap and then transfer image to the control's graphic context.
            using (GDIMemoryContext memGDI = new GDIMemoryContext(g, tabRect.Width, tabRect.Height))
            {
                Rectangle drawRect = new Rectangle(0, 0, tabRect.Width, tabRect.Height);
                rend.DrawBackground(memGDI.Graphics, drawRect);
                if (tabSelected && tabRect.X == 0)
                {
                    int corrY = memGDI.Height - 1;
                    memGDI.SetPixel(0, corrY, memGDI.GetPixel(0, corrY - 1));
                }

                /* An important moment. If tabs alignment is bottom, we should flip the image to display the tab
                 * correctly.*/
                if (this.Alignment == TabAlignment.Bottom)
                {
                    memGDI.FlipVertical();
                }

                TabPage pg = this.TabPages[index];//tab page whose tab we're drawing
                //trying to get a tab image if any
                Image pagePict = this.GetImageByIndexOrKey(pg.ImageIndex, pg.ImageKey);
                if (pagePict != null)
                {
                    //If tab image is present we should draw it.
                    Point imgLoc   = new Point(tabSelected ? 8 : 6, 2);
                    int   imgRight = imgLoc.X + pagePict.Width;

                    if (this.Alignment == TabAlignment.Bottom)
                    {
                        imgLoc.Y = drawRect.Bottom - pagePict.Height - (tabSelected ? 4 : 2);
                    }
                    if (RightToLeftLayout)
                    {
                        imgLoc.X = drawRect.Right - imgRight;
                    }
                    memGDI.Graphics.DrawImageUnscaled(pagePict, imgLoc);
                    //Correcting rectangle for drawing text.
                    drawRect.X += imgRight; drawRect.Width -= imgRight;
                }
                //drawing tab text
                TextRenderer.DrawText(memGDI.Graphics, pg.Text, this.Font, drawRect, rend.GetColor(ColorProperty.TextColor),
                                      TextFormatFlags.SingleLine | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                //If the tab has part under scroller we shouldn't draw that part.
                if (fUpDown.X > 0 && fUpDown.X >= tabRect.X && fUpDown.X < tabRect.Right)
                {
                    tabRect.Width -= tabRect.Right - fUpDown.X;
                }
                memGDI.DrawContextClipped(g, tabRect);
            }
        }
예제 #2
0
        /// <summary>
        /// Draws a single tab.
        /// </summary>
        /// <param name="g">A <see cref="T:System.Drawing.Graphics"/> object used to draw the tab control.</param>
        /// <param name="index">An index of the tab being drawn.</param>
        /// <param name="tabRect">A <see cref="T:System.Drawing.Rectangle"/> object specifying tab's bounds.</param>
        /// <param name="rend">A <see cref="T:System.Windows.Forms.VisualStyles.VisualStyleRenderer"/> object for rendering the tab.</param>
        private void DrawTabItem(Graphics g, int index, Rectangle tabRect, VisualStyleRenderer rend)
        {
            //if the scroller is visible and the tab is fully placed under it, we don't need to draw such tab
            if (fUpDown.X > 0 && tabRect.X >= fUpDown.X) return;

            bool tabSelected = rend.State == (int)TabItemState.Selected;
            // We will draw our tab on a bitmap and then transfer image to the control's graphic context.
            using (GDIMemoryContext memGDI = new GDIMemoryContext(g, tabRect.Width, tabRect.Height))
            {
                Rectangle drawRect = new Rectangle(0, 0, tabRect.Width, tabRect.Height);
                rend.DrawBackground(memGDI.Graphics, drawRect);
                if (tabSelected && tabRect.X == 0)
                {
                    int corrY = memGDI.Height - 1;
                    memGDI.SetPixel(0, corrY, memGDI.GetPixel(0, corrY - 1));
                }
                /* An important moment. If tabs alignment is bottom, we should flip the image to display the tab
                             * correctly.*/
                if (this.Alignment == TabAlignment.Bottom) memGDI.FlipVertical();

                TabPage pg = this.TabPages[index];//tab page whose tab we're drawing
                //trying to get a tab image if any
                Image pagePict = this.GetImageByIndexOrKey(pg.ImageIndex, pg.ImageKey);
                if (pagePict != null)
                {
                    //If tab image is present we should draw it.
                    Point imgLoc = new Point(tabSelected ? 8 : 6, 2);
                    int imgRight = imgLoc.X + pagePict.Width;

                    if (this.Alignment == TabAlignment.Bottom)
                        imgLoc.Y = drawRect.Bottom - pagePict.Height - (tabSelected ? 4 : 2);
                    if (RightToLeftLayout) imgLoc.X = drawRect.Right - imgRight;
                    memGDI.Graphics.DrawImageUnscaled(pagePict, imgLoc);
                    //Correcting rectangle for drawing text.
                    drawRect.X += imgRight; drawRect.Width -= imgRight;
                }
                //drawing tab text
                TextRenderer.DrawText(memGDI.Graphics, pg.Text, this.Font, drawRect, rend.GetColor(ColorProperty.TextColor),
                    TextFormatFlags.SingleLine | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                //If the tab has part under scroller we shouldn't draw that part.
                if (fUpDown.X > 0 && fUpDown.X >= tabRect.X && fUpDown.X < tabRect.Right)
                    tabRect.Width -= tabRect.Right - fUpDown.X;
                memGDI.DrawContextClipped(g, tabRect);

            }
        }