GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / GetFormFieldFontColor Method / GetFormFieldFontColor(Int32,Int32) Method
A unique form field identifier specifying a required form field object. You can obtain this identifier using these methods: AddRadioButtonFormField(Single,Single,Single,Single,String,String,PdfCheckBoxStyle,Byte,Byte,Byte), GetFormFieldId or GetFormFieldChildID.
The index of the required child radio button in a group. It must be a value from 0 to GetFormFieldChildCount-1.

It is simply a sequence index of a radio button in a group, it does not correspond to the unique form field's identifier.

Example





In This Topic
GetFormFieldFontColor(Int32,Int32) Method
In This Topic
Returns the color used to display the checkmark in a required form field, here a child radio button in a group. The radio button group is specified by its unique form field's identifier and it is related to the currently loaded PDF document.As said, this method is only applicable to radio buttons.

The font color attribute is not restricted to any form fields, meaning that this value also defines the color of the checkmark in the radio button field. Please note that every single child radio button in a group of radio buttons within a radio button field can have its own font attributes as well.

For further assistance, please refer to the PDF Reference, Section "Interactive Forms".

Syntax
'Declaration
 
Public Overloads Function GetFormFieldFontColor( _
   ByVal FieldId As Integer, _
   ByVal ChildIdx As Integer _
) As Color
public Color GetFormFieldFontColor( 
   int FieldId,
   int ChildIdx
)
public function GetFormFieldFontColor( 
    FieldId: Integer;
    ChildIdx: Integer
): Color; 
public function GetFormFieldFontColor( 
   FieldId : int,
   ChildIdx : int
) : Color;
public: Color GetFormFieldFontColor( 
   int FieldId,
   int ChildIdx
) 
public:
Color GetFormFieldFontColor( 
   int FieldId,
   int ChildIdx
) 

Parameters

FieldId
A unique form field identifier specifying a required form field object. You can obtain this identifier using these methods: AddRadioButtonFormField(Single,Single,Single,Single,String,String,PdfCheckBoxStyle,Byte,Byte,Byte), GetFormFieldId or GetFormFieldChildID.
ChildIdx
The index of the required child radio button in a group. It must be a value from 0 to GetFormFieldChildCount-1.

It is simply a sequence index of a radio button in a group, it does not correspond to the unique form field's identifier.

Return Value

The color of the displayed checkmark of a specified child radio button. The 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. At the same, this method is only meaningful for radio buttons, otherwise it will fail.

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

Just to inform you, that the attributes representing the font and its resources are defined for all form field objects by default. For further assistance, please refer to the PDF Reference, Section "Interactive Forms".

Example
How to find out the correct color of the checkmark defined for radio button fields.
Dim caption As String = "Example: GetFormFieldFontColor"
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 = "", ftitle As String = ""
        Dim formID As Integer = 0, kids As Integer = 0
        Dim hasRB As Boolean = False
        Dim fcolor As Color = Color.White
        Dim type As PdfFormFieldType = PdfFormFieldType.PdfFormFieldTypeUnknown
        For i As Integer = 0 To count - 1
            formID = gdpicturePDF.GetFormFieldId(i)
            If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
                message = (i + 1).ToString() + ".form field - GetFormFieldId() finished with the status: "
                Exit For
            End If
            type = gdpicturePDF.GetFormFieldType(formID)
            If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
                message = (i + 1).ToString() + ".form field - GetFormFieldType() finished with the status: "
                Exit For
            End If
            If type = PdfFormFieldType.PdfFormFieldTypeRadioButton Then
                hasRB = True
                ftitle = gdpicturePDF.GetFormFieldTitle(formID)
                If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
                    message = (i + 1).ToString() + ".form field - GetFormFieldTitle() finished with the status: "
                    Exit For
                End If
                fcolor = gdpicturePDF.GetFormFieldFontColor(formID)
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    'The font/text color is same for all child radio buttons in the given group.
                    message = message + ftitle + " radio button - font color is " + fcolor.ToString() + " - same for all children." + vbCrLf
                Else
                    If gdpicturePDF.GetStat() = GdPictureStatus.Aborted Then
                        'The font/text color is different for individual child radio buttons in the given group.
                        kids = gdpicturePDF.GetFormFieldChildCount(formID)
                        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
                            message = "The radio button " + ftitle + " - GetFormFieldChildCount() finished with the status: "
                            Exit For
                        End If
                        message = message + ftitle + " radio button - font/text color is different for child buttons." + vbCrLf
                        For j As Integer = 0 To kids - 1
                            fcolor = gdpicturePDF.GetFormFieldFontColor(formID, j)
                            If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
                                message = (j + 1).ToString() + ".child of " + ftitle + " - GetFormFieldFontColor() finished with the status: "
                                Exit For
                            End If
                            message = message + "  " + (j + 1).ToString() + ".child - font color: " + fsize.ToString() + vbCrLf
                        Next
                        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
                    Else
                        'This is an error in getting the font/text color.
                        message = "The radio button " + ftitle + " - GetFormFieldFontColor() finished with the status: " + gdpicturePDF.GetStat()
                        Exit For
                    End If
                End If
            End If
        Next
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            If count = 0 Then
                message = "This file doesn't include forms."
            ElseIf Not hasRB Then
                message = "This file doesn't include radio button form fields."
            End If
        Else
            message = message + gdpicturePDF.GetStat().ToString()
        End If
        MessageBox.Show(message, caption)
    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: GetFormFieldFontColor";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("forms.pdf", false) == GdPictureStatus.OK)
{
    int count = gdpicturePDF.GetFormFieldsCount();
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        string message = "", ftitle = "";
        int formID = 0, kids = 0;
        bool hasRB = false;
        Color fcolor = Color.White;
        PdfFormFieldType type = PdfFormFieldType.PdfFormFieldTypeUnknown;
        for (int i = 0; i < count; i++)
        {
            formID = gdpicturePDF.GetFormFieldId(i);
            if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
            {
                message = (i + 1).ToString() + ".form field - GetFormFieldId() finished with the status: ";
                break;
            }
            type = gdpicturePDF.GetFormFieldType(formID);
            if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
            {
                message = (i + 1).ToString() + ".form field - GetFormFieldType() finished with the status: ";
                break;
            }
            if (type == PdfFormFieldType.PdfFormFieldTypeRadioButton)
            {
                hasRB = true;
                ftitle = gdpicturePDF.GetFormFieldTitle(formID);
                if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
                {
                    message = (i + 1).ToString() + ".form field - GetFormFieldTitle() finished with the status: ";
                    break;
                }
                fcolor = gdpicturePDF.GetFormFieldFontColor(formID);
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    //The font/text color is same for all child radio buttons in the given group.
                    message = message + ftitle + " radio button - font color is " + fcolor.ToString() + " - same for all children.\n";
                }
                else
                {
                    if (gdpicturePDF.GetStat() == GdPictureStatus.Aborted)
                    {
                        //The font/text color is different for individual child radio buttons in the given group.
                        kids = gdpicturePDF.GetFormFieldChildCount(formID);
                        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
                        {
                            message = "The radio button " + ftitle + " - GetFormFieldChildCount() finished with the status: ";
                            break;
                        }
                        message = message + ftitle + " radio button - font color is different for child buttons.\n";
                        for (int j = 0; j < kids; j++)
                        {
                            fcolor = gdpicturePDF.GetFormFieldFontColor(formID, j);
                            if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
                            {
                                message = (j + 1).ToString() + ".child of " + ftitle + " - GetFormFieldFontColor() finished with the status: ";
                                break;
                            }
                            message = message + "  " + (j + 1).ToString() + ".child - font color: " + fsize.ToString() + "\n";
                        }
                        if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
                    }
                    else
                    {
                        //This is an error in getting the font/text color.
                        message = "The radio button " + ftitle + " - GetFormFieldFontColor() finished with the status: " + gdpicturePDF.GetStat();
                        break;
                    }
                }
            }
        }
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            if (count == 0) message = "This file doesn't include forms.";
            else if (!hasRB) message = "This file doesn't include radio button form fields.";
        }
        else message = message + gdpicturePDF.GetStat().ToString();
        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