Back to Devexpress

PdfGraphicsAcroFormListBoxField Class

officefileapi-devexpress-dot-pdf-0ba00bcd.md

latest7.0 KB
Original Source

PdfGraphicsAcroFormListBoxField Class

A list box field in PDF Graphics API.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Drawing.dll

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public class PdfGraphicsAcroFormListBoxField :
    PdfGraphicsAcroFormChoiceField
vb
Public Class PdfGraphicsAcroFormListBoxField
    Inherits PdfGraphicsAcroFormChoiceField

The following members return PdfGraphicsAcroFormListBoxField objects:

Remarks

To access the PdfGraphicsAcroFormComboBoxField class, you need to reference the DevExpress.Pdf.Drawing.v25.2 assembly.

Tip

You can use the PdfAcroFormField class to add interactive form fields to a PDF file. Refer to the following article for more information: Interactive Forms in PDF Documents

Create a List Box Field

To create a list box form field, create a new PdfGraphicsAcroFormListBoxField instance, and pass the field name and page location as constructor parameters. The page location is calculated in the world coordinate system.

You can also call the CreateListBox method to create a list box form field.

To add values to the list box, call one of the PdfGraphicsAcroFormChoiceField.AddValue overloaded methods.

Specify Form Field Parameters

The following parameters are available:

ParameterAPI
Form field nameName
Tooltip textToolTip
Selected item (by index)SetSelected(Int32, Boolean)
Selected item (by export value)SelectValue(String)
Multiple selectionMultiSelect
Appearance settings (background and foreground color, font and border options)Appearance

Add a Form Field as Graphics Content

To add a combo box field as graphics content, pass a PdfGraphicsAcroFormComboBoxField object as a parameter to the PdfGraphics.AddFormField method.

Draw a List Box Field on a Page

To add an interactive field to a page, call one of the following methods:

Example

This example uses PDF Graphics API to create a list box field and add it to a new PDF page.

View Example

csharp
using DevExpress.Pdf;
using System.Drawing;

//...
static void Main(string[] args)
{
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Create an empty document.
        processor.CreateEmptyDocument("..\\..\\Result.pdf");

        // Create graphics and draw a list box field.
        using (PdfGraphics graphics = processor.CreateGraphicsPageSystem())
        {
            DrawListBoxField(graphics);

            // Render a page with graphics.
            processor.RenderNewPage(PdfPaperSize.Letter, graphics);
        }
    }
}

static void DrawListBoxField(PdfGraphics graphics)
{
    // Create a list box field
    PdfGraphicsAcroFormListBoxField listBox = new PdfGraphicsAcroFormListBoxField("list box", new RectangleF(20, 20, 100, 120));

    // Add values to the list box.
    listBox.AddValue("Blue");
    listBox.AddValue("Green");
    listBox.AddValue("Red");
    listBox.AddValue("Yellow");

    // Specify list box parameters.
    listBox.Appearance.BackgroundColor = Color.Aqua;
    listBox.TextAlignment = PdfAcroFormStringAlignment.Far;
    listBox.SelectValue("Blue");

    // Add the field to the document.
    graphics.AddFormField(listBox);
}
vb
Imports DevExpress.Pdf
Imports System.Drawing

'...
Shared Sub Main(ByVal args() As String)
    Using processor As New PdfDocumentProcessor()

        ' Create an empty document.
        processor.CreateEmptyDocument("..\..\Result.pdf")

        ' Create graphics and draw a list box field.
        Using graphics As PdfGraphics = processor.CreateGraphicsPageSystem()
            DrawListBoxField(graphics)

            ' Render a page with graphics.
            processor.RenderNewPage(PdfPaperSize.Letter, graphics)
        End Using
    End Using
End Sub

Private Shared Sub DrawListBoxField(ByVal graphics As PdfGraphics)

    ' Create a list box field.
    Dim listBox As New PdfGraphicsAcroFormListBoxField("list box", New RectangleF(20, 20, 100, 120))

    ' Add values to the list box.
    listBox.AddValue("Blue")
    listBox.AddValue("Green")
    listBox.AddValue("Red")
    listBox.AddValue("Yellow")

    ' Specify list box parameters.
    listBox.Appearance.BackgroundColor = Color.Aqua
    listBox.TextAlignment = PdfAcroFormStringAlignment.Far
    listBox.SelectValue("Blue")

    ' Add the field to the document.
    graphics.AddFormField(listBox)
End Sub

Inheritance

Object PdfGraphicsAcroFormField PdfGraphicsAcroFormCommonField PdfGraphicsAcroFormChoiceField PdfGraphicsAcroFormListBoxField

See Also

PdfGraphicsAcroFormListBoxField Members

DevExpress.Pdf Namespace