Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

An advanced rendering class

0.00/5 (No votes)
15 Jul 2008 2  
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.

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.

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.
  • 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here