Skip to main content Skip to footer

Spread Windows Forms and Diagonal Borders

You may wish to draw attention to a cell. You can do this with diagonal lines in a cell or cell border with Spread for WinForms. You can use the ComplexBorder class to create diagonal border lines for a cell border as shown in the following image. complexbordercell Diagonal Border The following example displays diagonal lines in a cell. C#

FarPoint.Win.ComplexBorderSide topborder = new FarPoint.Win.ComplexBorderSide(System.Drawing.Color.Black, 1);  
FarPoint.Win.ComplexBorderSide leftborder = new FarPoint.Win.ComplexBorderSide(System.Drawing.Color.Blue, 1);  
FarPoint.Win.ComplexBorderSide rightborder = new FarPoint.Win.ComplexBorderSide(Color.Red, 2);  
FarPoint.Win.ComplexBorderSide bottomborder = new FarPoint.Win.ComplexBorderSide(Color.Black, 3, System.Drawing.Drawing2D.DashStyle.Solid, null, new float[] { 0f, 0.33f, 0.66f, 1f });  
FarPoint.Win.ComplexBorderSide dborder = new FarPoint.Win.ComplexBorderSide(System.Drawing.Color.Orange, 2);  
FarPoint.Win.ComplexBorder bord = new FarPoint.Win.ComplexBorder(leftborder, topborder, rightborder, bottomborder, dborder, true, true);  
fpSpread1.Sheets[0].Cells[1, 1].Border = bord;  

VB

Dim topborder As New FarPoint.Win.ComplexBorderSide(System.Drawing.Color.Black, 1)  
Dim leftborder As New FarPoint.Win.ComplexBorderSide(System.Drawing.Color.Blue, 1)  
Dim rightborder As New FarPoint.Win.ComplexBorderSide(Color.Red, 2)  
Dim bottomborder As New FarPoint.Win.ComplexBorderSide(Color.Black, 3, System.Drawing.Drawing2D.DashStyle.Solid, Nothing, New Single() {0, 0.33, 0.66, 1})  
Dim dborder As New FarPoint.Win.ComplexBorderSide(System.Drawing.Color.Orange, 2)  
Dim bord As New FarPoint.Win.ComplexBorder(leftborder, topborder, rightborder, bottomborder, dborder, True, True)  
FpSpread1.Sheets(0).Cells(1, 1).Border = bord  

You can create cell borders with diagonal lines as shown in the following image. diagonallines Diagonal Lines Try this example code to see a text cell with a diagonal border. C#

fpSpread1.Sheets[0].Cells[1, 3].Text = "Test"; //Cell has to have a value  
fpSpread1.Sheets[0].Cells[1, 3].Border = new FarPoint.Win.ComplexBorder(new FarPoint.Win.ComplexBorderSide(Color.Red, 2));// Cell has to have a border  
FarPoint.Win.Spread.CellType.TextCellType cellType = new FarPoint.Win.Spread.CellType.TextCellType();  
cellType.TextOrientation = FarPoint.Win.TextOrientation.TextRotateCustom;  
cellType.TextRotationAngle = 60; // Cell has to have rotation angle to see the effect.  
fpSpread1.Sheets[0].Cells[1, 3].CellType = cellType;  
fpSpread1.Sheets[0].EnableDiagonalLine = true;  

VB

FpSpread1.Sheets(0).Cells(1, 3).Text = "Test" 'Cell has to have a value  
FpSpread1.Sheets(0).Cells(1, 3).Border = New FarPoint.Win.ComplexBorder(New FarPoint.Win.ComplexBorderSide(Color.Red, 2)) ' Cell has to have a border  
Dim cellType As New FarPoint.Win.Spread.CellType.TextCellType()  
cellType.TextOrientation = FarPoint.Win.TextOrientation.TextRotateCustom  
cellType.TextRotationAngle = 60 ' Cell has to have rotation angle to see the effect.  
FpSpread1.Sheets(0).Cells(1, 3).CellType = cellType  
FpSpread1.Sheets(0).EnableDiagonalLine = True  

You can also display the diagonal lines in a cell border that is part of a shape as displayed in the following image. diagonalshape Diagonal Lines in a Shape The cell must have a border and the text orientation must not be zero. Try this example code to see a shape with a cell that has with a diagonal border. C#

fpSpread1.Sheets[0].Cells[1, 3].Text = "Test"; //Cell has to have a value  
fpSpread1.Sheets[0].Cells[1, 3].Border = new FarPoint.Win.ComplexBorder(new FarPoint.Win.ComplexBorderSide(Color.Red, 2));// Cell has to have a border  

FarPoint.Win.Spread.CellType.TextCellType cellType = new FarPoint.Win.Spread.CellType.TextCellType();  
cellType.TextOrientation = FarPoint.Win.TextOrientation.TextRotateCustom;  
cellType.TextRotationAngle = 60; // Cell has to have rotation angle to see the effect.  
fpSpread1.Sheets[0].Cells[1, 3].CellType = cellType;  

FarPoint.Win.Spread.DrawingSpace.TriangleShape a = new FarPoint.Win.Spread.DrawingSpace.TriangleShape();  
a.BackColor = Color.Blue;  
fpSpread1.ActiveSheet.AddShape(a, 1, 1);  
FarPoint.Win.Spread.DrawingSpace.SpreadCameraShape test = new FarPoint.Win.Spread.DrawingSpace.SpreadCameraShape();  
test.Formula = "B1:E6";  
test.Location = new System.Drawing.Point(20, 20);  
fpSpread1.Sheets[0].AddShape(test);  
fpSpread1.Sheets[0].EnableDiagonalLine = true;  

VB

FpSpread1.Sheets(0).Cells(1, 3).Text = "Test" 'Cell has to have a value  
FpSpread1.Sheets(0).Cells(1, 3).Border = New FarPoint.Win.ComplexBorder(New FarPoint.Win.ComplexBorderSide(Color.Red, 2)) ' Cell has to have a border  

Dim cellType As New FarPoint.Win.Spread.CellType.TextCellType()  
cellType.TextOrientation = FarPoint.Win.TextOrientation.TextRotateCustom  
cellType.TextRotationAngle = 60 ' Cell has to have rotation angle to see the effect.  
FpSpread1.Sheets(0).Cells(1, 3).CellType = cellType  

Dim a As New FarPoint.Win.Spread.DrawingSpace.TriangleShape()  
a.BackColor = Color.Blue  
FpSpread1.ActiveSheet.AddShape(a, 1, 1)  
Dim test As New FarPoint.Win.Spread.DrawingSpace.SpreadCameraShape()  
test.Formula = "B1:E6"  
test.Location = New System.Drawing.Point(20, 20)  
FpSpread1.Sheets(0).AddShape(test)  
FpSpread1.Sheets(0).EnableDiagonalLine = True  

MESCIUS inc.

comments powered by Disqus