Back to Devexpress

ButtonFormControl Interface

officefileapi-devexpress-dot-spreadsheet-e23091a1.md

latest5.9 KB
Original Source

ButtonFormControl Interface

A button form control.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

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

The following members return ButtonFormControl objects:

Remarks

Create a Button Form Control

The code sample below creates a button form control:

csharp
using DevExpress.Spreadsheet;

Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");
var cellRange = workbook.Worksheets[0].Range["B2:C4"];
var buttonFormControl = formControls.AddButton(cellRange);
buttonFormControl.PlainText = "Click Here";
buttonFormControl.PrintObject = false;
vb
Imports DevExpress.Spreadsheet

Dim workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")
Dim cellRange = workbook.Worksheets(0).Range("B2:C4")
Dim buttonFormControl = formControls.AddButton(cellRange)
buttonFormControl.PlainText = "Click Here"
buttonFormControl.PrintObject = False

Note

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

Obtain Button 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 Id and Name properties return the form control’s identifier and name.

Modify Button Form Controls

Use the ButtonFormControl class properties to change button form control parameters.

Note

The ShapeFormatBase.Fill and ShapeFormatBase.Outline properties return null for the ButtonFormControl.

The code sample below retrieves all button form controls from a worksheet and disables printing for all buttons:

csharp
using DevExpress.Spreadsheet;
using System.Linq;

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

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

var buttons = formControls.Where(formControl => formControl.FormControlType == FormControlType.Button).Cast<ButtonFormControl>();
foreach (ButtonFormControl button in buttons) {
    button.PrintObject = false;
}
vb
Imports DevExpress.Spreadsheet
Imports System.Linq

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

Dim formControls = workbook.Worksheets(0).FormControls

Dim buttons = formControls.Where(Function(formControl) formControl.FormControlType = FormControlType.Button).Cast(Of ButtonFormControl)()
For Each button As ButtonFormControl In buttons
  button.PrintObject = False
Next button

Remove Button Form Controls

Call the FormControlCollection.Remove or FormControlCollection.RemoveAt method to remove a form control.

The code sample below removes all buttons 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.Button)
        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.Button Then
    formControls.RemoveAt(i)
  End If
Next i

See Also

ButtonFormControl Members

DevExpress.Spreadsheet Namespace