A unique form field identifier specifying a required form field object. You can obtain this identifier using methods like GdPicturePDF.GetFormFieldId, GdPicturePDF.GetFormFieldChildID or methods intended to add form fields.
Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / FormFieldHasBackgroundColor Method / FormFieldHasBackgroundColor(Int32) Method

FormFieldHasBackgroundColor(Int32) Method

In This Topic
Returns, if the background (fill) color attribute is defined for a required form field, that is specified by its unique form field's identifier and it is related to the currently loaded PDF document.

The form field's background (fill) color attribute is not assigned automatically when creating the form field. However, you can specify the background color using the GdPicturePDF.SetFormFieldBackgroundColor method right after adding the required form field on the page. Otherwise, the form field may display invisible.

Be aware that if the background (fill) color differs for each single child radio button in a group of radio buttons within a radio button field, this method will fail. Please use the GdPicturePDF.FormFieldHasBackgroundColor method instead to find out, if the background (fill) color attribute is defined for each child radio button in a group.

Syntax
'Declaration

 

Public Overloads Function FormFieldHasBackgroundColor( _

   ByVal FieldId As Integer _

) As Boolean
public bool FormFieldHasBackgroundColor( 

   int FieldId

)
public function FormFieldHasBackgroundColor( 

    FieldId: Integer

): Boolean; 
public function FormFieldHasBackgroundColor( 

   FieldId : int

) : boolean;
public: bool FormFieldHasBackgroundColor( 

   int FieldId

) 
public:

bool FormFieldHasBackgroundColor( 

   int FieldId

) 

Parameters

FieldId
A unique form field identifier specifying a required form field object. You can obtain this identifier using methods like GdPicturePDF.GetFormFieldId, GdPicturePDF.GetFormFieldChildID or methods intended to add form fields.

Return Value

true if the background (fill) color attribute is defined for the specified form field object, otherwise false. The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GdPicturePDF.GetStat method to identify the specific reason for the method's failure, if any.

Just to remind you, that the form field's background (fill) color attribute is not assigned automatically when creating the form field.

Example
How to set the background color to only those form fields, which don't have any defined.
Dim caption As String = "Example: FormFieldHasBackgroundColor"

Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()

If gdpicturePDF.LoadFromFile("forms.pdf", False) = GdPictureStatus.OK Then

    Dim count As Integer = gdpicturePDF.GetFormFieldsCount()

    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then

        Dim message As String = ""

        Dim formID As Integer = 0

        Dim bkColor As Color = Color.Black

        Dim hasColor As Boolean = False

        Dim status As GdPictureStatus = GdPictureStatus.OK

        For i As Integer = 0 To count - 1

            message = message + i.ToString() + ".field: "

            formID = gdpicturePDF.GetFormFieldId(i)

            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then

                hasColor = gdpicturePDF.FormFieldHasBackgroundColor(formID)

                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then

                    message = message + "has bkColor: " + hasColor.ToString()

                    If hasColor Then

                        bkColor = gdpicturePDF.GetFormFieldBackgroundColor(formID)

                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then

                            message = message + "  bkColor: " + bkColor.ToString()

                        Else

                            message = message + "  bkColor: " + gdpicturePDF.GetStat().ToString()

                        End If

                    Else

                        If gdpicturePDF.SetFormFieldBackgroundColor(formID, Color.Fuchsia) = GdPictureStatus.OK Then

                            message = message + "  color set to: " + Color.Fuchsia.ToString()

                        Else

                            message = message + "  color set to: " + gdpicturePDF.GetStat().ToString()

                        End If

                    End If

                Else

                    message = message + gdpicturePDF.GetStat().ToString()

                End If

                status = GdPictureStatus.OK

            Else

                MessageBox.Show("The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)

                status = GdPictureStatus.Aborted

                Exit For

            End If

            message += vbCrLf

        Next

        If status = GdPictureStatus.OK Then

            If count = 0 Then

                MessageBox.Show("This file doesn't include forms.", caption)

            Else

                If gdpicturePDF.SaveToFile("forms_updated.pdf") = GdPictureStatus.OK Then

                    message = message + "The example has been followed successfully and the file has been saved."

                Else

                    message = message + "The file can't be saved."

                End If

                MessageBox.Show(message, caption)

            End If

        End If

    Else

        MessageBox.Show("The GetFormFieldsCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)

    End If

Else

    MessageBox.Show("The file can't be loaded.", caption)

End If

gdpicturePDF.Dispose()
string caption = "Example: FormFieldHasBackgroundColor";

GdPicturePDF gdpicturePDF = new GdPicturePDF();

if (gdpicturePDF.LoadFromFile("forms.pdf", false) == GdPictureStatus.OK)

{

    int count = gdpicturePDF.GetFormFieldsCount();

    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)

    {

        string message = "";

        int formID = 0;

        Color bkColor = Color.Black;

        bool hasColor = false;

        GdPictureStatus status = GdPictureStatus.OK;

        for (int i = 0; i < count; i++)

        {

            message = message + i.ToString() + ".field: ";

            formID = gdpicturePDF.GetFormFieldId(i);

            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)

            {

                hasColor = gdpicturePDF.FormFieldHasBackgroundColor(formID);

                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)

                {

                    message = message + "has bkColor: " + hasColor.ToString();

                    if (hasColor)

                    {

                        bkColor = gdpicturePDF.GetFormFieldBackgroundColor(formID);

                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)

                            message = message + "  bkColor: " + bkColor.ToString();

                        else

                            message = message + "  bkColor: " + gdpicturePDF.GetStat().ToString();

                    }

                    else

                    {

                        if (gdpicturePDF.SetFormFieldBackgroundColor(formID, Color.Fuchsia) == GdPictureStatus.OK)

                            message = message + "  color set to: " + Color.Fuchsia.ToString();

                        else

                            message = message + "  color set to: " + gdpicturePDF.GetStat().ToString();

                    }

                }

                else

                    message = message + gdpicturePDF.GetStat().ToString();

                status = GdPictureStatus.OK;

            }

            else

            {

                MessageBox.Show("The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);

                status = GdPictureStatus.Aborted;

                break;

            }

            message += "\n";

        }

        if (status == GdPictureStatus.OK)

        {

            if (count == 0)

                MessageBox.Show("This file doesn't include forms.", caption);

            else

            {

                if (gdpicturePDF.SaveToFile("forms_updated.pdf") == GdPictureStatus.OK)

                    message = message + "The example has been followed successfully and the file has been saved.";

                else

                    message = message + "The file can't be saved.";

                MessageBox.Show(message, caption);

            }

        }

    }

    else

        MessageBox.Show("The GetFormFieldsCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);

}

else

    MessageBox.Show("The file can't be loaded.", caption);

gdpicturePDF.Dispose();
See Also