Borders.DiagonalBorderColor Property
Gets or sets the line color of the cell diagonal border.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.2.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Property Value
Type | Description |
---|---|
Color | A Color value specifying the border line color. |
Remarks
To specify characteristics of cell diagonal borders, use the DiagonalBorderColor, Borders.DiagonalBorderLineStyle and Borders.DiagonalBorderType properties.
If you set a color and line style for a cell diagonal border and do not select the diagonal border type, the Borders.DiagonalBorderType property will be automatically set to DiagonalBorderType.UpAndDown. Use this diagonal border type if you want to specify both diagonal-up and diagonal-down borders for a cell. If it is required to set a cell diagonal border either from bottom left to top right or from top left to bottom right, change the Borders.DiagonalBorderType property value. Note that if you specify different formats for diagonal-up (DiagonalBorderType.Up) and diagonal-down (DiagonalBorderType.Down) borders separately, only the last specified diagonal border will be applied.
Another way to set diagonal borders for a cell or range of cells is to call the Borders.SetDiagonalBorders method with a border color, line style and type passed as parameters.
To specify any other cell borders (e.g., top, bottom, left, right, inside and outside borders), use the corresponding properties and methods of the Borders object. Access this object via the cell’s or cell range’s Formatting.Borders property.
- To specify borders of an individual cell, access the Borders object using the cell’s Formatting.Borders property directly.
- To specify borders of the cell range, modify the Borders object within the CellRange.BeginUpdateFormatting - CellRange.EndUpdateFormatting method pair.
- To share the same border settings between multiple cells in one step, apply the style with the specified borders to required cells. To specify borders for a cell style, access the Style object from the IWorkbook.Styles collection and use the Formatting.Borders property within the Formatting.BeginUpdate-Formatting.EndUpdate paired methods to access and modify the Borders object.
For examples on how to specify formatting for an individual cell and cell range, or modify a style, refer to the How to: Format a Cell or Range of Cells or How to: Create or Modify a Style document, respectively.
Example
This example demonstrates how to specify different borders for individual cells and ranges of cells by modifying the Borders object.
Worksheet worksheet = workbook.Worksheets[0];
// Set each particular border for the cell.
Cell cellB2 = worksheet.Cells["B2"];
Borders cellB2Borders = cellB2.Borders;
cellB2Borders.LeftBorder.LineStyle = BorderLineStyle.MediumDashDot;
cellB2Borders.LeftBorder.Color = Color.Pink;
cellB2Borders.TopBorder.LineStyle = BorderLineStyle.MediumDashDotDot;
cellB2Borders.TopBorder.Color = Color.HotPink;
cellB2Borders.RightBorder.LineStyle = BorderLineStyle.MediumDashed;
cellB2Borders.RightBorder.Color = Color.DeepPink;
cellB2Borders.BottomBorder.LineStyle = BorderLineStyle.Medium;
cellB2Borders.BottomBorder.Color = Color.Red;
cellB2Borders.DiagonalBorderType = DiagonalBorderType.Up;
cellB2Borders.DiagonalBorderLineStyle = BorderLineStyle.Thick;
cellB2Borders.DiagonalBorderColor = Color.Red;
// Set diagonal borders for the cell.
Cell cellC4 = worksheet.Cells["C4"];
Borders cellC4Borders = cellC4.Borders;
cellC4Borders.SetDiagonalBorders(Color.Orange, BorderLineStyle.Double, DiagonalBorderType.UpAndDown);
// Set all outside borders for the cell in one step.
Cell cellD6 = worksheet.Cells["D6"];
cellD6.Borders.SetOutsideBorders(Color.Gold, BorderLineStyle.Double);
// Set all borders for the range of cells in one step.
CellRange range1 = worksheet.Range["B8:F13"];
range1.Borders.SetAllBorders(Color.Green, BorderLineStyle.Double);
// Set all inside and outside borders separately for the range of cells.
CellRange range2 = worksheet.Range["C15:F18"];
range2.SetInsideBorders(Color.SkyBlue, BorderLineStyle.MediumDashed);
range2.Borders.SetOutsideBorders(Color.DeepSkyBlue, BorderLineStyle.Medium);
// Set all horizontal and vertical borders separately for the range of cells.
CellRange range3 = worksheet.Range["D21:F23"];
Formatting range3Formatting = range3.BeginUpdateFormatting();
Borders range3Borders = range3Formatting.Borders;
range3Borders.InsideHorizontalBorders.LineStyle = BorderLineStyle.MediumDashDot;
range3Borders.InsideHorizontalBorders.Color = Color.DarkBlue;
range3Borders.InsideVerticalBorders.LineStyle = BorderLineStyle.MediumDashDotDot;
range3Borders.InsideVerticalBorders.Color = Color.Blue;
range3.EndUpdateFormatting(range3Formatting);
// Set each particular border for the range of cell.
CellRange range4 = worksheet.Range["E25:F26"];
Formatting range4Formatting = range4.BeginUpdateFormatting();
Borders range4Borders = range4Formatting.Borders;
range4Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thick);
range4Borders.LeftBorder.Color = Color.Violet;
range4Borders.TopBorder.Color = Color.Violet;
range4Borders.RightBorder.Color = Color.DarkViolet;
range4Borders.BottomBorder.Color = Color.DarkViolet;
range4Borders.DiagonalBorderType = DiagonalBorderType.UpAndDown;
range4Borders.DiagonalBorderLineStyle = BorderLineStyle.MediumDashed;
range4Borders.DiagonalBorderColor = Color.BlueViolet;
range4.EndUpdateFormatting(range4Formatting);