SandRibbon User Guide

Rendering

Back to Table of Contents

Drawing and Measuring

SandRibbon components have their own separate drawing and measuring process that is linked to but distinct from that of normal controls.

A RenderingContext is used for the duration of each measuring and painting cycle. This is passed to all the relevant functions. The MeasureCore function is overridden by each component to return its desired size, based upon its properties and children if applicable. Two painting methods, DrawBackground and DrawForeground, are also overridden by most of the components. When writing your own SandRibbon components you should consider whether each part of your drawing falls in to background or foreground.

Part of the context you are passed for a drawing operation includes the most appropriate text color for components in the container you're in, and standard appropriate text formatting information for convenience.

Text Operations

Controls in SandRibbon render their text in either GDI+ or GDI depending on circumstances. To remain independent of either one in your code, you should use the IndependentText class we provide. Its static methods provide all the measuring and drawing functionality you will need.

If you are the .NET 1.x version GDI+ rendering will always be used. If you are using the .NET 2.0 version GDI will almost always be used, and is the default. We provide the TextFormattingInformation structure which, depending on the build you are using, contains a GDI+ StringFormat reference and optionally also a TextFormatFlags enumeration.

Alternatively, if you are building components specifically for one version of .NET you may wish to use the text drawing and measuring functions you are already familiar with.

Renderers

All the components shipped as part of SandRibbon defer most of their drawing to an instance of the RibbonRenderer class, which usually comes from the RibbonManager you are using. This class therefore has a lot of methods.

You can derive from RibbonRenderer and override any of these method if you want to change the way standard elements are drawn. Once you have derived and create your own custom renderer class, you can assign it to the Renderer property of your RibbonManager and it will take effect immediately.

This architecture gives you almost total control over the way every element is drawn.

Color Tables

The default renderer exposes a ColorTable property, of type Office2007ColorTable. This class contains entries for every color used by the default renderer to draw ribbon elements. These color properties can be changed individually should you wish to develop a custom color scheme for the ribbon in your applications.

Most customers, should they wish to customize drawing, will normally really only need to change the color table in use. It is only necessary to write a custom renderer if the actual elements being drawn need to be changed in some way beyond just their colors.

Next: Customization