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

A Serious Outlook Style Navigation Pane Control

, 15 Nov 2010
A quality rendered Outlook style navigation pane control
NaviBarDemo0.1.zip
NaviBarSource0.1.zip
Guifreaks.NavigationBar
Design
ClassDiagram02.cd
Guifreaks.NavigationBar.csproj.user
img
Down.png
Up.png
Key.snk
NaviBar.bmp
NaviGroup.bmp
Properties
Resources
DesignTimeText.xls
NavigationBarDemo
img
bookmark.png
colorize.png
contents.png
history.png
klipper.png
Thumbs.db
wizard.png
imgSmall
bookmark.png
colorize.png
history.png
klipper_dock.png
wizard.png
NavigationBarDemo.csproj.user
Properties
Settings.settings
Resources
Down.png
Up.png
Screenie.jpg
Build
Guifreaks.NavigationBar.XmlSerializers.dll
Guifreaks.Common
Guifreaks.Common.csproj.user
Key.snk
Properties
NavigationBarDemoAppVb.zip
NavigationBarDemoAppVb
bin
Debug
Guifreaks.Common.dll
Guifreaks.NavigationBar.dll
Guifreaks.NavigationBar.XmlSerializers.dll
NavigationBarDemoAppVb.exe
NavigationBarDemoAppVb.vshost.exe
My Project
Application.myapp
Settings.settings
Resources
bookmark.png
bookmark1.png
colorize.png
colorize1.png
Down.png
history.png
history1.png
klipper.png
klipper_dock.png
Up.png
wizard.png
wizard1.png
ThirdParty
Guifreaks.Common.dll
Guifreaks.NavigationBar.dll
Guifreaks.NavigationBar.XmlSerializers.dll
#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.Windows.Forms;

namespace Guifreaks.NavigationBar
{
   /// <summary>
   /// This class contains drawing functionality for the Navigation pane in the Outlook 2003
   /// style
   /// </summary>
   public class NaviBarRendererOff3 : NaviBarRenderer
   {
      #region Fields

      protected NaviColorTableOff3 colorTable;

      #endregion

      #region Constructor

      public NaviBarRendererOff3()
      {
         colorTable = new NaviColorTableOff3();
      }

      #endregion

      #region Properties

      /// <summary>
      /// Gets or sets the table of colors
      /// </summary>
      public NaviColorTableOff3 ColorTable
      {
         get { return colorTable; }
         set { colorTable = value; }
      }

      #endregion

      #region Methods

      /// <summary>
      /// Draws the background of the NavigationBar
      /// </summary>
      /// <param name="g">The graphics surface to draw on</param>
      /// <param name="bounds">The bounds of the background</param>
      /// <remarks>Its sufficient to supply the ClientRectangle property of the control</remarks>
      public override void DrawBackground(Graphics g, Rectangle bounds)
      {
         bounds.Width -= 1;
         bounds.Height -= 1;

         using (Brush b = new SolidBrush(Color.White))
         using (Pen p = new Pen(colorTable.DarkBorder))
         {
            g.FillRectangle(b, bounds);
            g.DrawRectangle(p, bounds);
         }
      }

      /// <summary>
      /// Draws the background of the rectangle containing the small buttons on the bottom 
      /// of the NavigationBar
      /// </summary>
      /// <param name="g">The graphics surface to draw on</param>
      /// <param name="bounds">The bounds of the small rectangle</param>
      public override void DrawSmallButtonRegion(Graphics g, Rectangle bounds)
      {
         // Background
         Color[] EndColors = { ColorTable.ButtonDark, ColorTable.ButtonLight };
         float[] ColorPositions = { 0.0f, 1.0f };

         ColorBlend blend = new ColorBlend();

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

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

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

         using (Pen p = new Pen(colorTable.DarkBorder))
         {
            g.DrawLine(p, bounds.Left, bounds.Top, bounds.Right, bounds.Top);
         }
      }

      /// <summary>
      /// Draws the header region on top of the NavigationBar
      /// </summary>
      /// <param name="g">The graphics surface to draw on</param>
      /// <param name="bounds">The bounds of the header</param>
      public override void DrawHeader(Graphics g, Rectangle bounds)
      {
         Color[] endColors = new Color[] { colorTable.HeaderBgDark, colorTable.HeaderBgLight };
         float[] ColorPositions = { 0.0f, 1.0f };

         ColorBlend blend = new ColorBlend();

         blend.Colors = endColors;
         blend.Positions = ColorPositions;

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

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

      /// <summary>
      /// Draws the text of the header region
      /// </summary>
      /// <param name="g">The canvas to draw on</param>
      /// <param name="bounds">The bounds of the text</param>
      /// <param name="text">The header text to draw</param>
      /// <param name="font">The font to use to draw the text</param>
      /// <param name="rightToLeft">indicates whether it's right to left or left to right layout</param>
      public override void DrawHeaderText(Graphics g, Rectangle bounds, string text, Font font, bool rightToLeft)
      {
         using (Brush brush = new SolidBrush(colorTable.Text))
         {
            if (rightToLeft)
            {
               TextRenderer.DrawText(g, text, font, bounds, colorTable.HeaderText,
                  TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis
                  | TextFormatFlags.Right | TextFormatFlags.RightToLeft);
            }
            else
            {
               TextRenderer.DrawText(g, text, font, bounds, colorTable.HeaderText,
                  TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
            }
         }
      }

      #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

About the Author

HawVie
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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 15 Nov 2010
Article Copyright 2009 by HawVie
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid