GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetFormFieldBackgroundColor Method / GetFormFieldBackgroundColor(Int32) Method
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
GetFormFieldBackgroundColor(Int32) Method
In This Topic
Returns the background (fill) color of 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 method only returns the correct form field's background (fill) color if this attribute is specified in the form field object itself, otherwise it will fail.

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.GetFormFieldBackgroundColor method to determine the individual background (fill) color for each child radio button in a group instead.

Syntax
'Declaration
 
Public Overloads Function GetFormFieldBackgroundColor( _
   ByVal FieldId As Integer _
) As GdPictureColor
public GdPictureColor GetFormFieldBackgroundColor( 
   int FieldId
)
public function GetFormFieldBackgroundColor( 
    FieldId: Integer
): GdPictureColor; 
public function GetFormFieldBackgroundColor( 
   FieldId : int
) : GdPictureColor;
public: GdPictureColor GetFormFieldBackgroundColor( 
   int FieldId
) 
public:
GdPictureColor GetFormFieldBackgroundColor( 
   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

The background (fill) color of the specified form field, if defined. 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.

Be aware that the form field's background (fill) color attribute is not assigned automatically when creating the form field. If this attribute is not specified, this method will fail.

Example
How to determine the background color of those form fields, which do have some defined.
Dim caption As String = "Example: GetFormFieldBackgroundColor"
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: GetFormFieldBackgroundColor";
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