Click here to Skip to main content
15,895,799 members
Articles / Desktop Programming / Windows Forms

A Serious Outlook Style Navigation Pane Control

Rate me:
Please Sign up or sign in to vote.
4.94/5 (135 votes)
15 Nov 2010CC (ASA 2.5)6 min read 1.3M   72.1K   518  
A quality rendered Outlook style navigation pane control
#region License and Copyright

/*
 
Author:  Jacob Mesu
 
Attribution-Noncommercial-Share Alike 3.0 Unported
You are free:

    * to Share — to copy, distribute and transmit the work
    * to Remix — to adapt the work

Under the following conditions:

    * Attribution — You must attribute the work and give credits to the author or guifreaks.net
    * Noncommercial — You may not use this work for commercial purposes. If you want to adapt
      this work for a commercial purpose, visit guifreaks.net and request the Attribution-Share 
      Alike 3.0 Unported license for free. 

http://creativecommons.org/licenses/by-nc-sa/3.0/

*/
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace Guifreaks.NavigationBar
{
   public class NaviGroupRendererOff7 : NaviGroupRenderer   
   {
      #region Fields

      NaviColorTableOff7 colorTable;

      #endregion

      #region Constructor

      public NaviGroupRendererOff7()
      {
         colorTable = new NaviColorTableOff7();
      }

      #endregion

      #region Properties

      /// <summary>
      /// Gets or sets the colors to draw the control with
      /// </summary>
      public NaviColorTableOff7 ColorTable
      {
         get { return colorTable; }
         set { colorTable = value; }
      }

      #endregion

      #region Methods

      public override void DrawBackground(Graphics g, Rectangle bounds)
      {
         using (Brush b = new SolidBrush(colorTable.Background))
         {
            g.FillRectangle(b, bounds);
         }
      }

      public override void DrawText(Graphics g, Rectangle bounds, Font font, string headerText, bool rightToLeft)
      {
         using (Brush brush = new SolidBrush(colorTable.Text))
         {
            if (rightToLeft)
            {
               TextRenderer.DrawText(g, headerText, font, bounds, colorTable.Text,
                  TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis |
                  TextFormatFlags.Right | TextFormatFlags.RightToLeft);
            }
            else
            {
               TextRenderer.DrawText(g, headerText, font, bounds, colorTable.Text,
                  TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
            }
         }
      }

      public override void DrawHeader(Graphics g, Rectangle bounds, InputState state, bool expanded, bool rightToLeft)
      {
         Color dark, light;
         bounds.Height--;

         if (state == InputState.Hovered)
         {
            dark = colorTable.GroupBgHoveredDark;
            light = colorTable.GroupBgHoveredLight;
         }
         else
         {
            dark = colorTable.GroupBgDark;
            light = colorTable.GroupBgLight;
         }

         // Background
         Color[] EndColors = { dark, light, dark };
         float[] ColorPositions = { 0.0f, .50f, 1.0f };

         ColorBlend blend = new ColorBlend();

         blend.Colors = EndColors;
         blend.Positions = ColorPositions;

         if (bounds.Width == 0)
            bounds.Width = 1; // its to prevent an out of memory exception

         //Make the linear brush and assign the custom blend to it
         using (LinearGradientBrush brush = new LinearGradientBrush(new Point(0, 0),
                                                           new Point(bounds.Width, 0),
                                                           Color.White,
                                                           Color.Black))
         {
            brush.InterpolationColors = blend;
            g.FillRectangle(brush, bounds);
         }

         using (Pen pen = new Pen(colorTable.DarkBorder))
         {
            // Dark border
            //g.DrawRectangle(pen, bounds);
            g.DrawLine(pen, new Point(0, 0), new Point(bounds.Width, 0));

            // Light line bottom
            pen.Color = colorTable.GroupBorderLight;
            g.DrawLine(pen, new Point(0, bounds.Height),
               new Point(bounds.Width, bounds.Height));

            // Light inner border
            pen.Color = colorTable.GroupInnerBorder;
            g.DrawLine(pen, new Point(0, 1), new Point(bounds.Width, 1));
            g.DrawLine(pen, new Point(0, 1), new Point(0, bounds.Height - 1));

            // Arrows
            pen.Color = colorTable.ShapesFront;

            //width-7
            //(height/2)+1
            // w=7 h=4
            pen.Width = 1.5f;
            float x = 0;
            float y = 0;

            if (bounds.Height != 0)
               y = (bounds.Height / 2) - 3; // + 1px border and - 4 size

            if (rightToLeft)
               x = 7;
            else
               x = bounds.Width - 7 - 7; // 7 px spacing and - 7 width            

            if (expanded)
            {
               PointF[] points = { new PointF(x, y + 3 + 4), 
                               new PointF(x + 3,y + 4), 
                               new PointF(x + 3 + 3, y + 3 + 4) };
               g.DrawLines(pen, points);

               PointF[] points2 = { new PointF(x, y + 3), 
                               new PointF(x + 3,y ), 
                               new PointF(x + 3 + 3, y + 3) };
               g.DrawLines(pen, points2);
            }
            else
            {
               PointF[] points = { new PointF(x, y + 4), 
                               new PointF(x + 3,y + 3 + 4), 
                               new PointF(x + 3 + 3, y + 4) };
               g.DrawLines(pen, points);

               PointF[] points2 = { new PointF(x, y ), 
                               new PointF(x + 3,y + 3 ), 
                               new PointF(x + 3 + 3, y) };
               g.DrawLines(pen, points2);
            }
         }

      }

      public override void DrawHatchedPanel(Graphics g, Rectangle bounds)
      {
         using (Pen pen = new Pen(colorTable.DashedLineColor))
         {
            pen.DashStyle = DashStyle.Dash;
            g.DrawRectangle(pen, bounds);
         }
      }
      #endregion

      #region Event Handling
      #endregion
   }
}

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 Creative Commons Attribution-ShareAlike 2.5 License


Written By
Architect
Netherlands Netherlands
I design software for a ERP software vendor in the Netherlands.

For more information, the latest version installer etc goto guifreaks.net

Comments and Discussions