# Formatting Font

## Content



You might want to change the appearance of the text in cell(s) so that the text stands out from the rest. In [C1FlexSheet](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.C1FlexSheet.html), you can easily format the font of text in a cell by changing the font style, font family, font size, and font color.

[SetCellFormat](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.C1FlexSheet.SetCellFormat.html) method is used to set the format for the cell in [C1FlexSheet](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.C1FlexSheet.html).

The following code uses [SetCellFormat](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.C1FlexSheet.SetCellFormat.html) method to change the font family of the font in a cell:

**vbnet**

```vbnet
If flex IsNot Nothing Then
   flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontFamily, 
                      fontFamilyCombo.SelectedValue)
End If
```

**csharp**

```csharp
if (flex != null)
    flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontFamily,
                       fontFamilyCombo.SelectedValue);
```

To change the font size, first you need to set the size limit of the font. The following code uses [SetCellFormat](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.C1FlexSheet.SetCellFormat.html) method to change the font size after setting the limit:

**vbnet**

```vbnet
If flex IsNot Nothing Then
   flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontSize,
                      fontSize.SelectedValue)
End If
```

**csharp**

```csharp
if (flex != null)
    flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontSize,
                       fontSize.SelectedValue);
```

The following code illustrates the use of **SetCellFormat** method to change the Font style:

**vbnet**

```vbnet
If flex IsNot Nothing Then
   Select Case fontStyle.SelectedValue.ToString()
      Case "Bold"
         flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontWeight, FontWeights.Bold)
         Exit Select
      Case "Italic"
         flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontStyle, FontStyles.Italic)
         Exit Select
      Case "BoldAndItalic"
         flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontWeight, FontWeights.Bold)
         flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontStyle, FontStyles.Italic)
         Exit Select
      Case Else
         flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontStyle, FontStyles.Normal)
         flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontWeight, FontWeights.Normal)
         Exit Select
   End Select
End If
```

**csharp**

```csharp
if (flex != null)
{
    switch (fontStyle.SelectedValue.ToString())
    {
        case "Bold": flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontWeight,
                                        FontWeights.Bold);
            break;
        case "Italic": flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontStyle,
                                          FontStyles.Italic);
            break;
        case "BoldAndItalic": flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontWeight,
                                                 FontWeights.Bold);
            flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontStyle, FontStyles.Italic);
            break;
        default: flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontStyle, FontStyles.Normal);
            flex.SetCellFormat(flex.Selection.Cells, CellFormat.FontWeight, FontWeights.Normal);
            break;
    }
}
```

You can create your own color picker using system colors and use its reference in the code to change the font color. The following code can then be used to change the font color:

**vbnet**

```vbnet
If flex IsNot Nothing Then
   flex.SetCellFormat(flex.Selection.Cells, CellFormat.Foreground,
                      New SolidColorBrush(obj))
End If
```

**csharp**

```csharp
if (flex != null)
    flex.SetCellFormat(flex.Selection.Cells, CellFormat.Foreground, new SolidColorBrush(obj));
```