Back to Devexpress

LabelFormControl Interface

officefileapi-devexpress-dot-spreadsheet-40b29860.md

latest5.9 KB
Original Source

LabelFormControl Interface

Label form control.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface LabelFormControl :
    FormControl,
    Shape,
    FloatingObject,
    ShapeFormatBase,
    TextFormControl
vb
Public Interface LabelFormControl
    Inherits FormControl,
             Shape,
             FloatingObject,
             ShapeFormatBase,
             TextFormControl

The following members return LabelFormControl objects:

Remarks

Create a Label Form Control

The code sample below creates a combo box control:

csharp
using DevExpress.Spreadsheet;

Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");

var cellRange = spreadsheetControl.Document.Worksheets[0].Range["B2:C2"];
var labelFormControl = formControls.AddLabel(cellRange);
labelFormControl.PlainText = "Label";
vb
Imports DevExpress.Spreadsheet

Dim workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")

Dim cellRange = spreadsheetControl.Document.Worksheets(0).Range("B2:C2")
Dim labelFormControl = formControls.AddLabel(cellRange)
labelFormControl.PlainText = "Label"

Note

The FormControlCollection.AddLabel method call adds a new item to both FormControlCollection and ShapeCollection.

Obtain Label Form Controls

The Worksheet.FormControls property obtains all form controls in a worksheet. You can use one of the following ways to obtain a specific form control:

The FormControl.Id and FormControl.Name properties return the form control’s identifier and name.

Modify Label Form Controls

Use the LabelFormControl class properties to change label form control parameters. The code sample below obtains all labels and locks them from editing:

csharp
using DevExpress.Spreadsheet;
using System.Linq;

Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");

var formControls = spreadsheetControl.Document.Worksheets[0].FormControls;

var labels = formControls.Where(formControl => formControl.FormControlType == FormControlType.Label).Cast<LabelFormControl>();
foreach (LabelFormControl label in labels)
{
    label.LockText = true;
}
vb
Imports DevExpress.Spreadsheet
Imports System.Linq

Private workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")

Dim formControls = spreadsheetControl.Document.Worksheets(0).FormControls

Dim labels = formControls.Where(Function(formControl) formControl.FormControlType = FormControlType.Label).Cast(Of LabelFormControl)()
For Each label As LabelFormControl In labels
  label.LockText = True
Next label

Note

ShapeFormatBase.Fill and ShapeFormatBase.Outline property returns null for LabelFormControl.

Remove Label Form Controls

Call the FormControlCollection.Remove or FormControlCollection.RemoveAt method to remove a form control. The FormControlCollection.Clear() method removes all form controls from a worksheet.

The code sample below removes all labels from a worksheet:

csharp
Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");

var formControls = workbook.Worksheets[0].FormControls;

for (int i = formControls.Count - 1; i >= 0; i--) {
    if (formControls[i].FormControlType == FormControlType.Label)
        formControls.RemoveAt(i);
}
vb
Dim workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")

Dim formControls = workbook.Worksheets(0).FormControls

For i As Integer = formControls.Count - 1 To 0 Step -1
  If formControls(i).FormControlType = FormControlType.Label Then
    formControls.RemoveAt(i)
  End If
Next i

See Also

LabelFormControl Members

DevExpress.Spreadsheet Namespace