SandGrid User Guide

Rendering

Back to Table of Contents

Text Operations

Grids rely heavily on text rendering, and SandGrid is no exception. When writing controls that sit on the Windows Forms model one has to cope with inconsistencies in text rendering, especially with a product such as this that is released for .NET 1.0 as well as .NET 2.0.

A full discussion of the pros and cons of GDI and GDI+ text rendering is beyond the scope of this document. The TextFormattingInformation structure is our technology independent way of controlling text formatting in SandGrid, and a GridColumn is responsible for creating an instance of this to control text rendered underneath it. It exposes StringFormat, a field containing an instance of StringFormat to control text rendering under GDI+, and if you're using the .NET 2.0 version of SandGrid, it also exposes TextFormatFlags for controlling GDI text rendering.

The companion to TextFormattingInformation is the IndependentText class in the Rendering namespace. Use the static methods on this to render text in a manner separate from one particular technology. SandGrid of course uses this exclusively internally. Performance of GDI text rendering through this method compared with the standard TextRenderer class is nearly double.

We need to support both kinds of text rendering (rather than one or the other) because of printing. Even when using .NET 2.0 with fast GDI text rendering, GDI+ needs to be used when printing because the .NET printing model is based upon GDI+. SandGrid abstracts this problem away from developers extending it by automating the switchover.

Fonts

Fonts are used in a hierarchical way when measuring and drawing text. By default only the SandGrid control itself has a font explicitly defined, and accessing the Font property of any element within will return that instance. However, fonts can be explicitly defined on any element if you need to. Rows can have their own fonts, as can columns, and even cells.

When accessing the Font property on an element, if it does not have one explicitly defined it requests one from its logical parent. A GridCell will return the font of its parent row, and a GridRow or GridColumn will return the font of its parent grid. The font used to render text in a cell depends on the UseRowFont property of its column. In some situations (for example a Newsreader) the font will change on a per-row basis (bold rows for unread messages). In other situations it will be a per-column font that is desired.

Printing

Printing services are made available through the Print, PrintPreview and PageSetup methods on the SandGrid control. The Print method can optionally show a configuration dialog before printing is started. A PrintDocument derived class is exposed via the PrintDocument property, if you need to do anything programmatically with the printing support.