[]
The CellStyle class encapsulates properties that control the appearance of grid cells. This information includes the background and foreground colors, font, text and image alignment, etc.
[TypeConverter(typeof(ExpandableObjectConverter))]
public class CellStyle
The Styles property exposes a collection of grid styles, and has methods for creating and removing styles from the grid.
You can create and define styles at design time, but right-clicking the grid and selecting the "Edit Styles" menu option.
Styles follow a hierarchical model similar to styles in Microsoft Word or in cascading style sheets. Every property in a CellStyle object may be left unassigned, in which case the value is inherited from a parent style. The parent style is usually the built-in Normal style.
To determine which elements are defined in a particular style, use the DefinedElements property.
When you modify the properties of a CellStyle object, all cells that use that style are automatically repainted to reflect the changes.
Styles may be assigned to CellRange, Row, and Column objects, as shown in the example below.
The example below creates three CellStyle objects and assigns them to grid rows, columns, and cell ranges.
// create style with red background
CellStyle cs = _flex.Styles.Add("red");
Style.BackColor = Color.Red;
// create style with green background
cs = _flex.Styles.Add("green");
Style.BackColor = Color.Green;
// create style with bold font
cs = _flex.Styles.Add("bold");
Style.Font = new Font("Tahoma", 8, FontStyle.Bold);
// assign red style to a column
_flex.Cols[3].Style = _flex.Styles["red"];
// assign green style to a row
_flex.Rows[3].Style = _flex.Styles["green"];
// assign bold style to a cell range
CellRange rg = _flex.GetCellRange(2, 2, 4, 4);
rg.Style = _flex.Styles["bold"];
After running this code, the third column of the grid will be painted with a red background. The third row will be painted with a green background. The cell at the intersection will be painted in red, because column styles have priority over row styles. The remaining style elements for these cells (font, alignment, etc) are not defined in the new styles and are automatically inherited from the parent style (Normal).
The cells around the intersection will have a bold font. The style that defines the bold font does not specify a background color, so that element is inherited from the parent style, which may be the "red", "green", or "normal" styles.
Name | Description |
---|---|
BackColor | Gets or sets the color used to paint the cell background. |
BackgroundImage | Gets or sets the style's background image. |
BackgroundImageLayout | Gets or sets the a value that determines how the style will scale and position background image. |
Border | Gets the CellBorder object associated with this style. |
ComboList | Gets or sets a pipe-delimited list of valid values. |
DataMap | Gets or sets an IDictionary used to associate cell values with display values. |
DataType | Gets or sets the data type for the style. |
DefinedElements | Gets or sets which elements are defined in this style. |
Display | Gets or sets whether to show images, text, or both. |
EditMask | Gets or sets the mask string used to edit values. |
Editor | Gets or sets the custom editor used to edit cells that have this style. |
Font | Gets or sets the font used to paint text in the cell. |
ForeColor | Gets or sets the color of the text in the cell. |
Format | Gets or sets the format string used to display values. |
ImageAlign | Gets or sets the image alignment. |
ImageMap | Gets or sets an IDictionary used to associate cell values with images. |
ImageSpacing | Gets or sets the space between images and text in a cell, in pixels. |
Margins | Gets or sets the margins between the edges of the cell and its contents, in pixels. |
Name | Gets or sets the style name. |
SearchBackColor | Gets or sets the background color of the searched text in the cell. |
StringFormat | Gets the StringFormat element used for rendering strings when the UseCompatibleTextRendering property is set to true. |
TextAlign | Gets or sets the text alignment. |
TextDirection | Gets or sets the text direction. |
TextEffect | Gets or sets the 3D effect used to paint text. |
Trimming | Gets or sets how long strings are trimmed to fit the cell. |
UserData | Gets or sets arbitrary user data associated with this style. |
WordWrap | Gets or sets whether long strings should automatically wrap within the cell. |
Name | Description |
---|---|
BuildString() | Returns a compact string representation of this CellStyle. |
BuildString(StyleElementFlags) | Returns a string representation of this CellStyle. |
Clear() | Clears all elements in this style. |
Clear(StyleElementFlags) | Clears selected elements from this style. |
Equals(object) | Determines whether two CellStyle objects are equal. |
GetContentRectangle(Rectangle) | Gets the content portion of a cell's rectangle. |
GetHashCode() | Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. |
GetImageRectangle(Rectangle, Image, Image) | Gets the image portion of a cell's rectangle. |
GetTextRectangle(Rectangle, Image, Image) | Gets the text portion of a cell's rectangle. |
MergeWith(CellStyle) | Copies all elements defined in a source style to this style. |
ParseString(string) | Rebuilds this style based on a description contained in a string. |
Render(Graphics, Rectangle, Image, DrawColorMode) | Renders a string and an image into a Graphics object using this style. |
Render(Graphics, Rectangle, string, DrawColorMode) | Renders a string and an image into a Graphics object using this style. |
Render(Graphics, Rectangle, string, Image, DrawCellFlags, DrawColorMode) | Renders a string and an image into a Graphics object using this style. |
Render(Graphics, Rectangle, string, Image, DrawColorMode) | Renders a string and an image into a Graphics object using this style. |
ResetFont() | |
ShouldSerializeFont() |