Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

An easy way to add a Ribbon Panel Office 2007 style

, 18 Apr 2007
GNU code of RibbonPanel, free software for personal and nonlucrative use, for rest please contact me
Prize winner in Competition "Best C# article of Mar 2007"
demo.zip
source.zip
Source
TabStripApp
archive
bin
Release
diagram.png
Example.exe
TabStripApp.pdb
TabStripApp.vshost.exe
TabStripControlLibrary.dll
TabStripControlLibrary.pdb
Properties
Settings.settings
Resources
advanced-directory.png
B_click.png
B_click1.png
B_click11.png
B_on.png
B_on1.png
B_on11.png
config-users.png
gnome-dev-harddisk-1394.png
gnome-dev-removable-usb.png
gnome-finance.png
gnome-netstatus-rx.png
gnome-searchtool-animation.png
gnome-starthere.png
logviewer.png
mozilla-thunderbird.png
pan.png
stock_contact.png
stock_mail-compose.png
stock_mail-druid.png
stock_mail-flag-for-followup-done.png
stock_mail-receive.png
stock_mail-receive1.png
stock_mail-send.png
stock_new-spreadsheet.png
stock_outbox.png
stock_weather-storm.png
Thumbs.db
xsane.png
TabStripControlLibrary
bin
Release
TabStripControlLibrary.dll
TabStripControlLibrary.pdb
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Forms.VisualStyles;
using System.Drawing.Drawing2D;

namespace TabStripApp {
    class TabStripProfessionalRenderer : ToolStripProfessionalRenderer {
 
        private const int BOTTOM_LEFT = 0;
        private const int TOP_LEFT = 1;
        private const int TOP_RIGHT = 2;
        private const int BOTTOM_RIGHT = 3;

        public TabStripProfessionalRenderer() {
            this.RoundedEdges = false;
        }


        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) {
            TabStrip tabStrip = e.ToolStrip as TabStrip;
            Tab tab = e.Item as Tab;

            if (tab == null) {
                base.OnRenderButtonBackground(e);
                return;
            }
            Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size);
            Graphics g = e.Graphics;
           

            // we want an even rise in the angle, for every pixel we have to go up, 
            // we need to go over one pixel.  This will give us a straig
            
            if (tabStrip != null) {
                Point[] tabPolygonPoints = new Point[] {
                            new Point(0, bounds.Bottom), // lower left hand corner
                            new Point(tab.Height,bounds.Top), // upper left hand corner
                            new Point(bounds.Right-1, bounds.Top), // upper right hand corner
                            new Point(bounds.Right-1, bounds.Bottom)  // lower right hand corner
                        };

                Point[] fillTabPolygonPoints = new Point[] {
                         tabPolygonPoints[BOTTOM_LEFT],
                         new Point(tabPolygonPoints[TOP_LEFT].X -2, tabPolygonPoints[TOP_LEFT].Y +2),
                         new Point(tabPolygonPoints[TOP_LEFT].X +2, tabPolygonPoints[TOP_LEFT].Y),
                         tabPolygonPoints[TOP_RIGHT],
                         tabPolygonPoints[BOTTOM_RIGHT]
                        };


                Color startColor = ColorTable.MenuStripGradientEnd;
                Color endColor = ColorTable.MenuStripGradientBegin;



                if (tab.Selected && !tab.Checked) {
                    startColor = ColorTable.ButtonSelectedGradientBegin;
                    endColor = ColorTable.ButtonSelectedGradientEnd;
                }
                using (Brush b = new LinearGradientBrush(bounds, startColor, endColor, LinearGradientMode.Vertical)) {
                    g.FillPolygon(b, fillTabPolygonPoints);
                }



               
               
                using (Pen outerBlueBorderPen = new Pen(ColorTable.ButtonSelectedBorder)) {
                    using (Pen innerWhiteBorderPen = new Pen(ColorTable.GripLight)) {
                        
                        //
                        // draw left edge 
                        //
                        //   Bw
                        //  Bw 
                        // Bw
                        Point edgeStart = tabPolygonPoints[BOTTOM_LEFT];
                        Point edgeStop = tabPolygonPoints[TOP_LEFT];
                        edgeStop.Offset(-2,2); // stop one pixels early.

                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);
                      
                        // draw white shadow line along left edge
                        edgeStart.Offset(1,0);
                        edgeStop.Offset(1,0);
                        g.DrawLine(innerWhiteBorderPen, edgeStart, edgeStop);

                        //
                        // draw rounded corner
                        //       TOP_LEFT
                        //          v
                        //          [BBBBBBBBBBBBBBBBBBBBBB] <- top edge
                        //        BB[wwwwwwwwwwwwwwwwwwwwww] <- top edge shadow  (row 2)
                        //      BBww                                             (row 3)
                        //     Bww                                               (row 4)


                        // draw row 2
                        edgeStart = tabPolygonPoints[TOP_LEFT];
                        edgeStart.Offset(0,1);
                        edgeStop = edgeStart;
                        edgeStop.X += 1;

                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);
                        
                        // draw row 3
                        edgeStart.Offset(-2, 1);
                        edgeStop.Offset(-2,1);
                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);
                        edgeStart.Offset(2, 0);
                        edgeStop.Offset(2,0);
                        g.DrawLine(innerWhiteBorderPen, edgeStart, edgeStop);

                        // draw row 4
                        edgeStart.Offset(-2, 1);
                        edgeStop.Offset(-2, 1);
                        g.DrawLine(innerWhiteBorderPen, edgeStart, edgeStop);
                       
                        //
                        // draw top edge
                        //
                        //       TOP_LEFT
                        //          v
                        //          [BBBBBBBBBBBBBBBBBBBBBB] <- top edge
                        //        BB[wwwwwwwwwwwwwwwwwwwwww] <- top edge shadow  (row 2)


                        edgeStart = tabPolygonPoints[TOP_LEFT];
                        edgeStop = tabPolygonPoints[TOP_RIGHT];

                        // scoot over two pixels
                        edgeStart.Offset(2, 0);
                        edgeStop.Offset(-2, 0);

                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);

                        // scoot down to paint white shadow line
                        edgeStart.Offset(0, 1);
                        edgeStop.Offset(0, 1);
                        g.DrawLine(innerWhiteBorderPen, edgeStart, edgeStop);


                        //
                        // draw right edge
                        //          TOP_RIGHT
                        //              v
                        //            bB
                        //              bB
                        //              bB
                        //              bB
                        
                        edgeStart = new Point (tabPolygonPoints[TOP_RIGHT].X, tabPolygonPoints[TOP_RIGHT].Y+2);
                        edgeStop = tabPolygonPoints[BOTTOM_RIGHT];
                        
                        // draw dark blue lines
                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);
                        using (Brush b = new SolidBrush(outerBlueBorderPen.Color)) {
                            g.FillRectangle(b,new Rectangle(edgeStart.X - 1, edgeStart.Y - 1, 1, 1));
                        }

                        // draw light blue lines
                        using (Pen innerBlueBorderPen = new Pen(ColorTable.ButtonPressedHighlight)) {
                            edgeStart.Offset(-1, 0);
                            edgeStop.Offset(-1, 0);
                            g.DrawLine(innerBlueBorderPen, edgeStart, edgeStop);
                            using (Brush b = new SolidBrush(innerBlueBorderPen.Color)) {
                                g.FillRectangle(b, new Rectangle(edgeStart.X - 1, edgeStart.Y - 1, 1, 1));
                            }

                        }
                    }
                }

                
                tabPolygonPoints[0].Offset(1, 0);
                tabPolygonPoints[1].Offset(1, 0);

            }
            else {
                base.OnRenderButtonBackground(e);
            }

        }

      
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) {
           TabStrip tabStrip = e.ToolStrip as TabStrip;
           
            using (Pen outerBlueBorderPen = new Pen(ColorTable.ButtonSelectedBorder)) {
                using (Pen innerWhiteBorderPen = new Pen(ColorTable.GripLight)) {
                    if (tabStrip != null) {
                        if (tabStrip.SelectedTab != null) {
                            // left border coords
                            Point borderStart1 = new Point(0, tabStrip.SelectedTab.Bounds.Bottom);
                            Point borderStop1 = new Point(tabStrip.SelectedTab.Bounds.Left, tabStrip.SelectedTab.Bounds.Bottom);

                            // right border coords
                            Point borderStart2 = new Point(tabStrip.SelectedTab.Bounds.Right - 1, tabStrip.SelectedTab.Bounds.Bottom);
                            Point borderStop2 = new Point(tabStrip.ClientRectangle.Right, tabStrip.SelectedTab.Bounds.Bottom);
                           
                            e.Graphics.DrawLine(outerBlueBorderPen,borderStart1, borderStop1);
                            e.Graphics.DrawLine(outerBlueBorderPen,borderStart2, borderStop2);
                            
                            // shift all points down one to draw the white line
                            borderStop1.Offset(0,1);
                            borderStart1.Offset(0,1);
                            borderStart2.Offset(0,1);
                            borderStop2.Offset(0,1);
                            e.Graphics.DrawLine(innerWhiteBorderPen, borderStart1, borderStop1);
                            e.Graphics.DrawLine(innerWhiteBorderPen, borderStart2, borderStop2);
                      
                        }

                    }
                }
            }
            
        }
        
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Juan Pablo G.C.
Software Developer Expediteapps
Spain Spain
I'm Electronic Engineer, I did my end degree project at Astrophysical Institute and Tech Institute. I'm HP Procurve AIS and ASE ,Microsoft 3.5 MCTS
I live in Canary Islands ,developing customized solutions
 
I'm developing with WPF4, SL4 MVVM, MVC3 Razor and WP7 projects, more info at my websites. Improving with Android and IOS.
 
Web:
Expediteapps


Take a look to my blog Juan Pablo G.C.
Mareinsula

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 18 Apr 2007
Article Copyright 2007 by Juan Pablo G.C.
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid