Spread for Windows Forms Quick Start (6) --- define the appearance of cells

Source: Internet
Author: User

In Spread, each cell can be considered as an independent object. developers can not only set the cell type, but also set different appearance attributes for each cell.

Set cell color

You can set the background color and foreground text color for one or more cells. The example shows how to set the color in different ways. The code for creating the color of these cells is also given below.

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image002 "border =" 0 "alt =" clip_image002 "width =" 326 "height =" 148 "src =" http://www.bkjia.com/uploads/allimg/131228/1T4562263-0.jpg "/>

You can specify the background color for the cell by using the BackColor attribute of the cell in the code, and use the ForeColor attribute to specify the text color. If these cells are selected, you can also specify these colors by using SelectionBackColor and SelectionForeColor for the form. Using the LockBackColor and LockForeColor attributes of a form or appearance object, you can also specify a different color background color or text color in the locked cell ).

This sample code sets the background color and text color for the second cell, and sets the color for the lock cell and the selected cell.

FpSpread1.ActiveSheet. Cells [0, 1]. Value = "This is default .";

FpSpread1.ActiveSheet. Cells [1, 1]. Value = "This is M .";

FpSpread1.ActiveSheet. Cells [2, 1]. Value = "This is locked .";

FpSpread1.ActiveSheet. Cells [3, 1]. Value = "This is selected .";

FpSpread1.ActiveSheet. Cells [1, 1]. BackColor = Color. LimeGreen;

FpSpread1.ActiveSheet. Cells [1, 1]. ForeColor = Color. Yellow;

FpSpread1.ActiveSheet. Cells [2, 1]. Locked = true;

FpSpread1.ActiveSheet. Protect = true;

FpSpread1.ActiveSheet. LockBackColor = Color. Brown;

FpSpread1.ActiveSheet. LockForeColor = Color. Orange;

FpSpread1.ActiveSheet. SelectionStyle = FarPoint. Win. Spread. SelectionStyles. SelectionColors;

FpSpread1.ActiveSheet. SelectionPolicy = FarPoint. Win. Spread. Model. SelectionPolicy. Range;

FpSpread1.ActiveSheet. SelectionUnit = FarPoint. Win. Spread. Model. SelectionUnit. Cell;

FpSpread1.ActiveSheet. SelectionBackColor = Color. Pink;

FpSpread1.ActiveSheet. SelectionForeColor = Color. Red;

Set a background image for a cell

You can customize the background of a cell by adding a graphic image.

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image004 "border =" 0 "alt =" clip_image004 "width =" 418 "height =" 242 "src =" http://www.bkjia.com/uploads/allimg/131228/1T4564M4-1.jpg "/>

The sample code is as follows:

Private void Form1_Load (object sender, System. EventArgs e)

{

// Create an instance of a text cell.

FarPoint. Win. Spread. CellType. TextCellType t = new FarPoint. Win. Spread. CellType. TextCellType ();

// Load an image file and set it to BackgroundImage property.

FarPoint. Win. Picture p = new FarPoint. Win. Picture (Image. FromFile ("D: \ images \ lionstatue.jpg"), FarPoint. Win. RenderStyle. Stretch );

T. BackgroundImage = p;

// Apply the text cell.

FpSpread1.ActiveSheet. Cells [1, 1]. CellType = t;

// Set the size of the cell so the image is displayed

FpSpread1.ActiveSheet. Rows [1]. Height = 50;

FpSpread1.ActiveSheet. Columns [1]. Width = 150;

}

Customize cell boundaries

You can customize the appearance of a cell for one or more cells by setting the boundary. You can set the boundary for a column, row, form, or group of cells, but the set effect is the same as that for alignment of each independent cell. For a group of cells, the same Boundary object is applied to each cell. You need to use the Border attribute of the cell class, the Border attribute of the column class, or the Border attribute of the row class to set the boundary.

You can specify more than one style and color for the same cell, column, row, or group of cells. The cell boundary in the form is drawn from left to right and from top to bottom. If two adjacent borders have different styles or colors, the last drawn boundary is given priority and displayed. The cell boundary reflects the priority enjoyed by the form. This priority determines the features of the form element. In this priority order, cell settings take precedence over row, column, and form settings.

The following table summarizes different cell border styles.

Style

Example

Description

FarPoint. Win Class Name

Inclined

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image006 "border =" 0 "alt =" clip_image006 "width =" 74 "height =" 35 "src =" http://www.bkjia.com/uploads/allimg/131228/1T45CW7-2.jpg "/>

If different colors are set for highlight and shadow, a three-dimensional appearance is generated.

BevelBorder

Compound

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image008 "border =" 0 "alt =" clip_image008 "width =" 74 "height =" 34 "src =" http://www.bkjia.com/uploads/allimg/131228/1T45611Z-3.jpg "/>

Different colors and types can be displayed on the border of each side of a cell. The border style includes dotted lines and dotted lines.

ComplexBorder

Hybrid

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image010 "border =" 0 "alt =" clip_image010 "width =" 74 "height =" 35 "src =" http://www.bkjia.com/uploads/allimg/131228/1T45A1b-4.jpg "/>

There are two oblique boundaries that can be separated by borders.

CompoundBorder

Dual Line

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image012 "border =" 0 "alt =" clip_image012 "width =" 78 "height =" 38 "src =" http://www.bkjia.com/uploads/allimg/131228/1T4561E1-5.jpg "/>

There are two parallel lines.

DoubleLineBorder

Single Line boundary

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image014 "border =" 0 "alt =" clip_image014 "width =" 74 "height =" 35 "src =" http://www.bkjia.com/uploads/allimg/131228/1T45A141-6.jpg "/>

There is a common single line.

LineBorder

Single line at the rounded edge

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image016 "border =" 0 "alt =" clip_image016 "width =" 74 "height =" 34 "src =" http://www.bkjia.com/uploads/allimg/131228/1T45C009-7.jpg "/>

There is a single line, but its corner is circle.

RoundedLineBorder

The difference between a boundary and a grid line is that the boundary is enclosed by one or more cells, without distinguishing rows and columns, and the boundary is drawn on the Grid line. If you want to display borders for all cells in the form, you can disable gridline display by setting the form attributes HorizontalGridLine and VerticalGridLine to None.

This sample code creates a boundary and sets the boundary to cells:

// Create the bevel border.

FarPoint. Win. BevelBorder bevelbrdr = new FarPoint. Win. BevelBorder (FarPoint. Win. BevelBorderType. Raised, Color. Cyan, Color. DarkCyan );

// Set the bevel border to the cell B3 border.

FpSpread1.Sheets [0]. Cells [4, 3]. Border = bevelbrdr;

Cell content

You can determine how the content is aligned in one or more cells. In the code, you only need to set the HorizontalAlignment and verticalignment attributes, and use CellHorizontalAlignment and cellverticalignment to enumerate.

In this sample code, set cell A1 to the right alignment in the horizontal direction and the lower alignment in the vertical direction. Cells B2 to C3 are both in the center of the horizontal vertical direction.

FpSpread1.Sheets [0]. Cells [0, 0]. HorizontalAlignment = FarPoint. Win. Spread. CellHorizontalAlignment. Right;

FpSpread1.Sheets [0]. Cells [0, 0]. verticalignment = FarPoint. Win. Spread. CellVerticalAlignment. Bottom;

FpSpread1.Sheets [0]. Cells [1, 1, 2, 2]. HorizontalAlignment = FarPoint. Win. Spread. CellHorizontalAlignment. Center;

FpSpread1.Sheets [0]. Cells [,]. verticalignment = FarPoint. Win. Spread. CellVerticalAlignment. Center;

Shows the execution result:

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" clip_image018 "border =" 0 "alt =" clip_image018 "width =" 519 "height =" 341 "src =" http://www.bkjia.com/uploads/allimg/131228/1T45631A-8.gif "/>

 

Appendix: Spread for Windows Forms Quick Start Series

Spread for Windows Forms Quick Start (1) --- getting started with Spread

Spread for Windows Forms Quick Start (2) --- setting Spread Forms

Spread for Windows Forms Quick Start (3) --- row and column operations

Spread for Windows Forms Quick Start (4) --- common cell types)

Spread for Windows Forms Quick Start (5) --- under common cell types)

This article from the "grape city control blog" blog, please be sure to keep this source http://powertoolsteam.blog.51cto.com/2369428/633981

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.