The CellViewerManager (or child) class can be derived from to use a control to display the content of a cell, or to provide custom painting for cell's foreground and/or background.
The CellViewerManager class exposes a protected virtual "Core" version of most of the public methods (for example, GetFittedWidthCore). When deriving from this class, the "Core" methods can be overridden to add to or replace their existing behavior. The events associated with each method are not raised by the "Core" version of the method but rather by the public "non-Core" version (for example, the corresponding GetFittedWidth method). However, even if the base implementation is not called in the "Core" version, the associated event will still be raised after the "Core" method is called. For example, if the GetFittedWidthCore method of the CellViewerManager class is overridden and the base implementation ignored, the GetFittedWidth method will still be called (by the underlying private implementation) and the QueryFittedWidth event will be raised.
The CellViewerManager (or child) class can be derived from to allow a control to display the content of a cell. The appearance of the underlying control can be defined through the SetControlAppearanceCore method while the value assigned to the control can be manipulated through the SetControlValueCore method (see the TrackBarViewer class).
The height and width required by the custom CellViewerManager is determined by the values returned by the GetFittedWidth and GetFittedHeight methods. In order to specify the fitted width and height of the underlying control, the GetFittedWidthCore and GetFittedHeightCore methods must be overridden and the appropriate values returned. If the values returned by these methods is -1, then the cell's width and height will be used.
The CellViewerManager class offers two ways to provide custom painting for a cell's content: override the GetImageCore and/or GetTextCore methods to return the image and text to be displayed by the custom CellViewerManager, or override the PaintCellForeground and/or PaintCellBackground methods to modify the way the cell's is painted.
For example, if a CellViewerManager were to be created to display a different image depending on a boolean value, the GetImageCore method could be overridden and return the appropriate image (see the BooleanImageTextViewer class example). In this case, it is more efficient to simply return the image rather than repainting the cell's foreground or background by overriding the PaintCellForeground and/or PaintCellBackground methods.
The default values of the ImageArea, ImageSize, ImagePadding, and TextPadding properties can be modified through the DefaultImageArea, DefaultImageSize, DefaultImagePadding, and DefaultTextPadding properties. In the case where GetImageCore is overridden, it is important to also override DefaultImageArea to return a value other than None. It is suggested that a static instance of the image returned by the GetImageCore method be used rather than creating a new instance everything the GetImageCore method is called.
The CalculateAreas method can be used to calculate the image and text rectangles based, among other things, on the values of the ImagePadding and TextPadding properties.
By overriding the PaintCellForeground and/or PaintCellBackground methods, the CellViewerManager can modify the appearance of the cell's foreground and/or background (see the PaintingViewer class example). In both cases, the Handled parameter must be set to true otherwise the cell will paint its own foreground and/or background and ignore the behavior stipulated by the CellViewerManager's PaintCellForeground and/or PaintCellBackground overrides.
When generating a report using the reporting capabilities of Xceed Grid for WinForms, CellViewerManagers will only be reproduced in the report if the GetImage and/or GetText methods return the image or text that is to be displayed ( GetImageCore and/or GetTextCore have been overridden). In the case where the GetImageCore and/or GetTextCore methods have not been overridden to return the desired image and/or text, the string representation of the underlying cell's content will be displayed in the report.
The following classes demonstrates how to derive from the CellViewerManager class to create custom CellViewerManagers: