Click here to Skip to main content
15,886,026 members
Articles / Programming Languages / C#
Article

An advanced rendering class

Rate me:
Please Sign up or sign in to vote.
4.65/5 (22 votes)
14 Jul 2008CPOL3 min read 78.3K   3.3K   102   19
A rendering class with full customizations for novice or advanced users.

EasyRender

Introduction

Many beginners in the C# or VB.NET development category sometimes want to be able to apply themes or styles to their application. This rendering class allows you to easily customize the appearance of your C#/VB.NET applications.

Background

This was inspired by the Office2007Renderer, which enables you to apply a multitude of Office 2007 styles to an application. After I began using Office2007Renderer, I found that some of the drawing functions caused severe lag on my applications. So, I took it into my own hands to develop a new Office2007Renderer of my own. From there, it developed into a fully editable class.

Using the code

The EasyRender class is easy to use and easy to customize. Unlike other rendering classes, I have divided each section of the renderer into sub-classes that you can then edit further.

C#
public Main()
{
      InitializeComponent();

      EasyRender Render = new EasyRender();

      ToolStripManager.Renderer = Render;
}

Basically, this initializes the rendering class and applies it to the ToolStripManager, and by default, Office2007 is the default theme style. Changes can be made via the Render variable though.

C#
public Main()
{
      InitializeComponent();

      EasyRender Render = new EasyRender();
      Render.Toolstrip.Curve = 2;
      Render.Toolstrip.BackgroundTop = Color.FromArgb(255, 255, 255);
      Render.Toolstrip.BackgroundBottom = Color.FromArgb(230, 230, 230);

      ToolStripManager.Renderer = Render;
}

This modification will adjust the background gradient colors for the Toolstrip control. The Curve property simply means the curve of the borders of the Toolstrip. It's suggested you don't enter a value over 4 for the Curve property, otherwise it becomes distorted.

You may want to alter the way the gradient is displayed. There are two key properties in almost every class, named BackgroundBlend and BackgroundAngle.

  • BackgroundAngle simply enables you to alter the direction in which the background gradient will be drawn.
  • BackgroundBlend is a System.Drawing.Drawing2D.Blend property. If you set this value to null, then no blending will occur. Otherwise, you can set it to a Blend value and it will draw the background with the specified blend. See below for a better idea.
  • C#
    Blend backBlend = new Blend();
    backBlend.Positions = new float[] { 0, 0.1, 0.4, 0.8, 1 };
    backBlend.Factors = new float[] { 0, 0.3, 0.6, 0.7, 0.2 };
    Render.Toolstrip.BackgroundBlend = backBlend;

For those who are not familiar with the Blend class, it simply works like an advanced gradient manager. Positions is an array of float values. Each value within it represents a position (0 to 1 means 0% to 100% of the overall length).

The Factors property specifies the intensity of the Color2 color of the gradient brush used to draw the background. So, a factor of "0" means the color is fully Color1 (or BackgroundTop), and "1" means the color is fully Color2 (or BackgroundBottom). Very handy indeed.

The rest is very easy to work out. SmoothText simply applies a smoothing effect to all text on any control that has ManagerRenderMode applied to it (which you have to apply to the StatusBar and ContentPanel controls). AlterColor simply denotes that all text affected by the renderer should use a set color, which can be defined by the OverrideColor property.

Points of Interest

A little note you may need to bear in mind is that I lost interest in this project around two months ago, so I haven't touched it since then. After I checked the code again, I saw that practically everything was in-tact. But, some of the features may not be fully implemented just yet, or there may be conversion or casting errors. If you find any, please do let me know and I'll fix it up immediately.

So, experiment with this if you want. I'll be adding an export feature when I get the time, and I'll also be adding a "Save as theme file" feature, so you can export them to a file and share them if you want.

License

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


Written By
Chief Technology Officer
United Kingdom United Kingdom
Software developer for 18 years, established in both Java and C# development. Ambitious, rambunctious, perhaps a little bit impracticable. Spaghetti toast.

Comments and Discussions

 
Questionabout the tooltip Pin
rojaldearintok17-Jan-15 21:11
rojaldearintok17-Jan-15 21:11 
QuestionAppearance almost identical?? Pin
i0021-Oct-14 1:10
i0021-Oct-14 1:10 
Questiondrop down arrow (grippy) color Pin
Ivan Ičin4-Jul-12 11:11
Ivan Ičin4-Jul-12 11:11 
QuestionComboBox Pin
dherrmann13-Oct-11 11:46
dherrmann13-Oct-11 11:46 
GeneralMy vote of 3 Pin
Dave Kreskowiak21-Jun-11 16:46
mveDave Kreskowiak21-Jun-11 16:46 
GeneralF***ing Cool !!! Pin
iccb101315-Jul-09 16:46
iccb101315-Jul-09 16:46 
QuestionForm Background? Pin
LukeFrankin.com8-Oct-08 0:14
LukeFrankin.com8-Oct-08 0:14 
AnswerRe: Form Background? Pin
viciouskinid9-Apr-09 13:43
viciouskinid9-Apr-09 13:43 
GeneralQuestion about the Menu Pin
rikidude5-Sep-08 5:56
rikidude5-Sep-08 5:56 
GeneralGenius! Pin
rokoprc26-Jul-08 21:50
rokoprc26-Jul-08 21:50 
GeneralBehaviour differ from standard renderers Pin
Eugene Sichkar20-Jul-08 12:48
Eugene Sichkar20-Jul-08 12:48 
GeneralContextMenuStrip item with subitems drawn incorrectly Pin
tonyt16-Jul-08 12:24
tonyt16-Jul-08 12:24 
GeneralProblem with checked menu items Pin
tonyt15-Jul-08 10:20
tonyt15-Jul-08 10:20 
GeneralRe: Problem with checked menu items Pin
Chris Copeland16-Jul-08 0:17
mveChris Copeland16-Jul-08 0:17 
GeneralOutstanding [modified] Pin
tonyt15-Jul-08 6:04
tonyt15-Jul-08 6:04 
GeneralRe: Thanks. Pin
Chris Copeland15-Jul-08 6:07
mveChris Copeland15-Jul-08 6:07 
GeneralRe: Outstanding Pin
LukeFrankin.com7-Oct-08 22:57
LukeFrankin.com7-Oct-08 22:57 
GeneralCool Pin
leppie15-Jul-08 0:38
leppie15-Jul-08 0:38 
GeneralRe: Cool Pin
rcollina15-Jul-08 1:41
rcollina15-Jul-08 1:41 

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

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