Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

Whidbey Style in VC++ 2005

2.56/5 (10 votes)
27 Dec 2006CPOL1 min read 2   371  
Whidbey style with ProfessionalColorTable class
Sample Image - Whidbey_Style.png

Introduction

It is known that the components MenuStrip,ToolStrip, StatusStrip improve the "old" Windows menus system, controls and its appearance.

With VS 2005, now we can decide the global style of an application simply inheriting the "public ref class ProfessionalColorTable" and overriding the appropriate class properties.

In this way, we can have our own style of application's menus and controls.

This is a great feature that demonstrates once again the power and flexibility of .NET 2.0.

The WhidbeyStyle class is a VC++ managed class that mimics the Microsoft Whidbey style.

But how to implement this inherited class in VC++ 2005 ?

I said that the ancestor class is the ProfessionalColorTable.

The ProfessionalColorTable class belongs at namespace System.Windows.Forms and "provides colors used for Microsoft Office display elements" (see MSDN).

I also said that it is a "ref class".

So What is a ref Class ?

A "ref class" is defined in C++/CLI language and is a managed class type. A reference class does not have a default copy constructor or a default assignment operator. So our new derived class will be a ref class and inherit the ProfessionalColorTable class.

The syntax is:

C++
ref class our_nameclass : public ProfessionalColorTable {  //... code }.  

The derived class must override the ProfessionalColorTable members.

The syntax is:

C++
//...code    
public:    property virtual Color MenuStripGradientBegin
{                  
  Color get()       override 
{                     
  return System::Drawing::ColorTranslator::FromWin32(0x00D7E5E5);           
}      
}     
//...  

where MenuStripGradientBegin is a public member of ProfessionalColorTable (see MSDN).

In the head of header file, we must write the directives:

C++
using namespace System::Windows::Forms;

using namespace System::Drawing;

because ProfessionalColorTable is defined in System::Windows::Forms and Color in Windows::System::Drawing.

The WhidbeyStyle Class Code

C++
using namespace System::Windows::Forms;
using namespace System::Drawing;

#pragma once
ref class WhidbeyStyle : public ProfessionalColorTable
{
public:
property virtual Color MenuStripGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00D7E5E5);
}
}

property virtual Color MenuStripGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00E7F2F3);
}
}

property virtual Color MenuItemSelected 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00EED2C1);
}
}

property virtual Color MenuBorder 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x007A868A);
}
}

property virtual Color MenuItemBorder 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00C56A31);
}
}

property virtual Color ToolStripDropDownBackground 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00F9FCFC);
}
}

property virtual Color ImageMarginGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00FBFEFE);
}
}

property virtual Color ImageMarginGradientMiddle 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(RGB(242,242,238));
}
}

property virtual Color ImageMarginGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00ACC3C4);
}
}

property virtual Color MenuItemSelectedGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00EFD3C6);
}
}

property virtual Color MenuItemSelectedGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00EFD3C6);
}
}

property virtual Color MenuItemPressedGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00F9FCFC);
}
}

property virtual Color MenuItemPressedGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00F9FCFC);
}
}

property virtual Color SeparatorDark 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00B8C2C5);
}
}

property virtual Color ToolStripGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00F5F9FA);
}
}

property virtual Color ToolStripGradientMiddle 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00EBEEEF);
}
}

property virtual Color ToolStripGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00A8C0C0);
}
}

property virtual Color ButtonSelectedGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00EFD3C6);
}
}

property virtual Color ButtonSelectedGradientMiddle 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00EFD3C6);
}
}

property virtual Color ButtonSelectedGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00EFD3C6);
}
}

property virtual Color ButtonSelectedBorder 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00C56A31);
}
}

property virtual Color ButtonPressedGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00E2B598);
}
} 

property virtual Color ButtonPressedGradientMiddle 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00E2B598);
}
}

property virtual Color ButtonPressedGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00E2B598);
}
}

property virtual Color ToolStripPanelGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00D7E5E5);
}
}

property virtual Color ToolStripPanelGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00E7F2F3);
}
}

property virtual Color ToolStripBorder 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00828F92);
}
}

property virtual Color OverflowButtonGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00EBEEEF);
}
}

property virtual Color OverflowButtonGradientMiddle 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(RGB(211,211,194));
}
}

property virtual Color OverflowButtonGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x007E9898);
}
}

property virtual Color StatusStripGradientBegin 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00A8C0C0);
}
}

property virtual Color StatusStripGradientEnd 
{
Color get() override
{
return System::Drawing::ColorTranslator::FromWin32(0x00F5F9FA);
}
}
};

Usage

  1. Add in your project the WhidbeyStyle class;
  2. Add an #include "WhidbeyStyle.h" directive in Main_Form_Name.h file of your project;
  3. In form_name_Load event handler, write the code:
C#
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
{
ToolStripManager::Renderer = gcnew ToolStripProfessionalRenderer(gcnew WhidbeyStyle()); 
}

In this way, the application's style is rendered in Whidbey style.

That's all.

History

  • 27th December, 2006: Initial post

License

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