# Coloring a Cell

Learn how to customize cell colors in Spread.NET with code examples and step-by-step instructions.

## Content

You can set the background and foreground (text) colors for a cell or for a group of cells. An example of the different ways to set the colors for a cell is shown in the following figure. The code that created these cell colors is provided in the example.
![Cell Colors Example](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/cell-colors.png)
You can specify the background color for a cell in code by using the [BackColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.BackColor.html) property for that cell. You can specify the text color in code by using the [ForeColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.ForeColor.html) property.
You can also specify the colors to display when the cells are selected using [SelectionBackColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SelectionBackColor.html) and [SelectionForeColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SelectionForeColor.html) for the sheet. For more information on selections, refer to [Customizing the Selection Appearance](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-interactselection/spwin-selsetappear).
You can also specify a different color (for background or for text) in locked cells using the [LockBackColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.LockBackColor.html) and [LockForeColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.LockForeColor.html) properties of the SheetView or Appearance objects. For more information on locked cells, refer to [Locking a Cell](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cell-focus/spwin-celllock).

## Using the Properties Window

1. At design time, in the **Properties** window, select the Spread component.
2. Select the **Sheets** property.
3. Click the button to display the **SheetView Collection Editor**.
4. In the **Members** list, select the sheet in which the cells appear.
5. In the properties list, select the **Cells** property and then click the button to display the **Cell, Column, and Row Editor**.
6. Select the cells for which you want to set the color.
7. In the properties list, select the **BackColor** property and select a color from the **Custom**, **Web**, or **System** tab. Select the **ForeColor** property and select that color.
8. Click **OK** to close the **Cell, Column, and Row Editor**.
9. Click **OK** to close the **SheetView Collection Editor**.

## Using a Shortcut

Set the [BackColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.BackColor.html) property or the [ForeColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.ForeColor.html) property for the Cells object.
**Example**
This example code sets the background color and text color for the second cell, sets the colors for locked cells, and sets the colors for selections.

```csharp
fpSpread1.ActiveSheet.Cells[0,1].Value = "This is default.";
fpSpread1.ActiveSheet.Cells[1,1].Value = "This is custom.";
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;
```

```vbnet
fpSpread1.ActiveSheet.Cells(0,1).Value = "This is default."
fpSpread1.ActiveSheet.Cells(1,1).Value = "This is custom."
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
```

## Using Code

Set the [BackColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.BackColor.html) property or the [ForeColor](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.ForeColor.html) property for a [Cell](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.html) object.
**Example**
This example code sets the background color for cell A1 to Azure and the foreground color to Navy, then sets the background color for cells C3 through D4 to Bisque.

```csharp
FarPoint.Win.Spread.Cell cellA1;
cellA1 = fpSpread1.ActiveSheet.Cells[0, 0];
cellA1.BackColor = Color.Azure;
cellA1.ForeColor = Color.Navy;
FarPoint.Win.Spread.Cell cellrange;
cellrange = fpSpread1.ActiveSheet.Cells[2,2,3,3];
cellrange.BackColor = Color.Bisque;
```

```vbnet
Dim cellA1 As FarPoint.Win.Spread.Cell
cellA1 = fpSpread1.ActiveSheet.Cells(0, 0)
cellA1.BackColor = Color.Azure
cellA1.ForeColor = Color.Navy
Dim cellrange As FarPoint.Win.Spread.Cell
cellrange = fpSpread1.ActiveSheet.Cells(2, 2, 3, 3)
cellrange.BackColor = Color.Bisque
```

## Using the Spread Designer

1. In the work area, select the cell or cells for which you want to set the background color.
2. In the properties list (in the **Misc** category), select the **BackColor** property to set the background color.
3. Click the drop-down button to display the color picker and choose the color from the available colors.
4. To set the text color, repeat those steps and select **ForeColor** property in the properties list.
5. From the **File** menu choose **Apply and Exit** to apply your changes to the component and exit Spread Designer.

## See Also

[Setting the Background Colors for a Sheet](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-setappearance/spwin-appearsheet/spwin-sheetbackcolor)
[Setting a Background Image for a Sheet](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-setappearance/spwin-appearsheet/spwin-sheetbackimage)
[Setting a Background Image to a Cell](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-setappearance/spwin-appearsheet/spwin-cell-backimage)