Click here to Skip to main content
Click here to Skip to main content

Whidbey Style in VC++ 2005

, 27 Dec 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
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:

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

The derived class must override the ProfessionalColorTable members.

The syntax is:

//...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:

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

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:
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)

Share

About the Author

Giuseppe Pischedda
Software Developer (Senior)
Italy Italy
No Biography provided
Follow on   Google+

Comments and Discussions

 
GeneralPerfect! PinmemberScottHackett24-Sep-07 5:43 
GeneralThank you! PinmemberAkashicOne12319-Jan-07 6:31 
GeneralUseless PinmemberAnton Afanasyev27-Dec-06 10:42 
AnswerRe: Useless PinmemberGiuseppe Pischedda27-Dec-06 23:01 
GeneralRe: Useless PinmemberMMansonFan2526-Feb-07 8:59 
QuestionAn article ? PinmemberPurplet27-Dec-06 7:35 
AnswerRe: An article ? [modified] PinmemberGiuseppe Pischedda27-Dec-06 22:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 27 Dec 2006
Article Copyright 2006 by Giuseppe Pischedda
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid