GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / AddRadioButtonFormField Method / AddRadioButtonFormField(Single,Single,Single,Single,String,String,PdfCheckBoxStyle,Color) Method
The horizontal (X) coordinate of the closest point to the currently defined origin, where the form field's bounding box is to be located. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
The vertical (Y) coordinate of the closest point to the currently defined origin, where the form field's bounding box is to be located. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
The width of the form field's bounding box, expressed in the current units specified by the SetMeasurementUnit method.
The height of the form field's bounding box, expressed in the current units specified by the SetMeasurementUnit method.
The name of the group, which includes the newly added child radio button. All child radio buttons with the same GroupName identify a group of related buttons.
The name of the child radio button in a group. It is recommended to set a unique value for each of the child radio buttons within one group.
A member of the PdfCheckBoxStyle enumeration. The style of the checkmark to be used to display a checked radio button (the on state). Please note that the first added child radio button in a group is automatically selected as on.
A color object that defines the color to be used for displaying the radio button's checkmark.
Example





In This Topic
AddRadioButtonFormField(Single,Single,Single,Single,String,String,PdfCheckBoxStyle,Color) Method
In This Topic
Adds a radio button form field to the currently selected page of the loaded PDF document according to what you have specified. Radio button fields are typically grouped into a set of related buttons, in which can each be on or off. Only one child radio button in a group may be on at any time and selecting another one in this group automatically deselects the previous one, if the RadiosInUnison flag is not set. The first added child radio button in a group is selected as on after the successful creation. If the RadiosInUnison flag is set, no child radio button in a group is selected by default.

All radio buttons added within the same group are handled as one form field object after the successful creation. You can determine the number of child radio buttons in a group by using the GetFormFieldChildCount method. To access the individual child objects, please use their corresponding sequence index according to that order, in which they have been added to the group.

This method uses the RGB color space for specifying the required color of the displayed radio button's checkmark.

You can subsequently use other methods for assigning more form field properties, as it is shown in the Example section below.

Syntax
'Declaration
 
Public Overloads Function AddRadioButtonFormField( _
   ByVal Left As Single, _
   ByVal Top As Single, _
   ByVal Width As Single, _
   ByVal Height As Single, _
   ByVal GroupName As String, _
   ByVal FieldName As String, _
   ByVal Style As PdfCheckBoxStyle, _
   ByVal CheckMarkColor As Color _
) As Integer
public int AddRadioButtonFormField( 
   float Left,
   float Top,
   float Width,
   float Height,
   string GroupName,
   string FieldName,
   PdfCheckBoxStyle Style,
   Color CheckMarkColor
)
public function AddRadioButtonFormField( 
    Left: Single;
    Top: Single;
    Width: Single;
    Height: Single;
    GroupName: String;
    FieldName: String;
    Style: PdfCheckBoxStyle;
    CheckMarkColor: Color
): Integer; 
public function AddRadioButtonFormField( 
   Left : float,
   Top : float,
   Width : float,
   Height : float,
   GroupName : String,
   FieldName : String,
   Style : PdfCheckBoxStyle,
   CheckMarkColor : Color
) : int;
public: int AddRadioButtonFormField( 
   float Left,
   float Top,
   float Width,
   float Height,
   string* GroupName,
   string* FieldName,
   PdfCheckBoxStyle Style,
   Color CheckMarkColor
) 
public:
int AddRadioButtonFormField( 
   float Left,
   float Top,
   float Width,
   float Height,
   String^ GroupName,
   String^ FieldName,
   PdfCheckBoxStyle Style,
   Color CheckMarkColor
) 

Parameters

Left
The horizontal (X) coordinate of the closest point to the currently defined origin, where the form field's bounding box is to be located. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
Top
The vertical (Y) coordinate of the closest point to the currently defined origin, where the form field's bounding box is to be located. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
Width
The width of the form field's bounding box, expressed in the current units specified by the SetMeasurementUnit method.
Height
The height of the form field's bounding box, expressed in the current units specified by the SetMeasurementUnit method.
GroupName
The name of the group, which includes the newly added child radio button. All child radio buttons with the same GroupName identify a group of related buttons.
FieldName
The name of the child radio button in a group. It is recommended to set a unique value for each of the child radio buttons within one group.
Style
A member of the PdfCheckBoxStyle enumeration. The style of the checkmark to be used to display a checked radio button (the on state). Please note that the first added child radio button in a group is automatically selected as on.
CheckMarkColor
A color object that defines the color to be used for displaying the radio button's checkmark.

Return Value

The unique identifier of the newly created radio button form field. 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.

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

Please always ensure that you have selected the correct page using the SelectPage method before adding a required form field.

Just to remind you, that the first added child radio button in a group is automatically selected as on (assuming the RadiosInUnison flag is not set).

You also need to be aware that the values of coordinates and dimensions are expressed in the current units defined by the SetMeasurementUnit method according to the current coordinate space defined by the SetOrigin method.

Example
How to add two groups of radio button form fields on the first page of the newly created PDF document.
Dim caption As String = "Example: AddRadioButtonFormField"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If (gdpicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
   (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    'Please always select the required page before adding a form field.
    If gdpicturePDF.SelectPage(1) = GdPictureStatus.OK Then
        Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
        If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetLineColor(Color.Black) = GdPictureStatus.OK) Then
            Dim formID As Integer = 0
            Dim buttonName As String = "RadioButton"
            'Creating the first group of radio buttons.
            If gdpicturePDF.DrawRectangle(0.5F, 0.5F, 4, 4, False, True) = GdPictureStatus.OK Then
                Dim colors1 As String() = New String() {"RED", "GREEN", "BLUE"}
                For i As Integer = 0 To colors1.Length - 1
                    formID = gdpicturePDF.AddRadioButtonFormField(1, 1 + i, 1, 1, "Group1", buttonName + (i+1).ToString(), PdfCheckBoxStyle.PdfCheckBoxStyleStar, Color.Black)
                    If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) OrElse
                       (gdpicturePDF.SetFormFieldBackgroundColor(formID, Color.Bisque) <> GdPictureStatus.OK) OrElse
                       (gdpicturePDF.SetFormFieldBorderColor(formID, Color.Brown) <> GdPictureStatus.OK) OrElse
                       (gdpicturePDF.DrawText(fontResName, 2.5F, 1.65F + i, colors1(i)) <> GdPictureStatus.OK) Then
                        MessageBox.Show("1.group: adding the radio button nr." + (i+1).ToString() + " has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
                        'stop creating anything
                        Exit For
                    End If
                Next
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    'Creating the second group of radio buttons.
                    If gdpicturePDF.DrawRectangle(5.5F, 0.5F, 5, 5, False, True) = GdPictureStatus.OK Then
                        Dim colors2 As String() = New String() {"CYAN", "MAGENTA", "YELLOW", "BLACK"}
                        For i As Integer = 0 To colors2.Length - 1
                            formID = gdpicturePDF.AddRadioButtonFormField(6, 1 + i, 1, 1, "Group2", buttonName + (i+1).ToString(), PdfCheckBoxStyle.PdfCheckBoxStyleCircle, Color.Black)
                            If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) OrElse
                               (gdpicturePDF.SetFormFieldBackgroundColor(formID, Color.Bisque) <> GdPictureStatus.OK) OrElse
                               (gdpicturePDF.SetFormFieldBorderColor(formID, Color.Brown) <> GdPictureStatus.OK) OrElse
                               (gdpicturePDF.DrawText(fontResName, 7.5F, 1.65F + i, colors2(i)) <> GdPictureStatus.OK) Then
                                MessageBox.Show("2.group: adding the radio button nr." + (i+1).ToString() + " has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
                                'stop creating anything
                                Exit For
                            End If
                        Next
                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                            If gdpicturePDF.SaveToFile("forms_radiobutton.pdf") = GdPictureStatus.OK Then
                                MessageBox.Show("The example has been followed successfully and the file has been saved.", caption)
                            Else
                                MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption)
                            End If
                        End If
                    Else
                        MessageBox.Show("The 2.DrawRectangle() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
                    End If
                End If
            Else
                MessageBox.Show("The 1.DrawRectangle() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
            End If
        Else
            MessageBox.Show("The AddStandardFont() or the SetLineColor() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
        End If
    Else
        MessageBox.Show("The SelectPage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
Else
    MessageBox.Show("The file can't be created.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: AddRadioButtonFormField";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if ((gdpicturePDF.NewPDF() == GdPictureStatus.OK) &&
    (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
    //Please always select the required page before adding a form field.
    if (gdpicturePDF.SelectPage(1) == GdPictureStatus.OK)
    {
        string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
        if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
            (gdpicturePDF.SetLineColor(Color.Black) == GdPictureStatus.OK))
        {
            int formID = 0;
            string buttonName = "RadioButton";
            //Creating the first group of radio buttons.
            if (gdpicturePDF.DrawRectangle(0.5f, 0.5f, 4, 4, false, true) == GdPictureStatus.OK)
            {
                string[] colors1 = new string[] { "RED", "GREEN", "BLUE" };
                for (int i = 0; i < colors1.Length; i++)
                {
                    formID = gdpicturePDF.AddRadioButtonFormField(1, 1 + i, 1, 1, "Group1", buttonName + (i+1).ToString(), PdfCheckBoxStyle.PdfCheckBoxStyleStar, Color.Black);
                    if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) ||
                        (gdpicturePDF.SetFormFieldBackgroundColor(formID, Color.Bisque) != GdPictureStatus.OK) ||
                        (gdpicturePDF.SetFormFieldBorderColor(formID, Color.Brown) != GdPictureStatus.OK) ||
                        (gdpicturePDF.DrawText(fontResName, 2.5f, 1.65f + i, colors1[i]) != GdPictureStatus.OK))
                    {
                        MessageBox.Show("1.group: adding the radio button nr." + (i+1).ToString() + " has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
                        break; //stop creating anything
                    }
                }
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    //Creating the second group of radio buttons.
                    if (gdpicturePDF.DrawRectangle(5.5f, 0.5f, 5, 5, false, true) == GdPictureStatus.OK)
                    {
                        string[] colors2 = new string[] { "CYAN", "MAGENTA", "YELLOW", "BLACK" };
                        for (int i = 0; i < colors2.Length; i++)
                        {
            
                            formID = gdpicturePDF.AddRadioButtonFormField(6, 1 + i, 1, 1, "Group2", buttonName + (i+1).ToString(), PdfCheckBoxStyle.PdfCheckBoxStyleCircle, Color.Black);
                            if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) ||
                                (gdpicturePDF.SetFormFieldBackgroundColor(formID, Color.Bisque) != GdPictureStatus.OK) ||
                                (gdpicturePDF.SetFormFieldBorderColor(formID, Color.Brown) != GdPictureStatus.OK) ||
                                (gdpicturePDF.DrawText(fontResName, 7.5f, 1.65f + i, colors2[i]) != GdPictureStatus.OK))
                            {
                                MessageBox.Show("2.group: adding the radio button nr." + (i+1).ToString() + " has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
                                break; //stop creating anything
                            }
            
                        }
                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        {
                            if (gdpicturePDF.SaveToFile("forms_radiobutton.pdf") == GdPictureStatus.OK)
                                MessageBox.Show("\nThe example has been followed successfully and the file has been saved.", caption);
                            else
                                MessageBox.Show("\nThe example has been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption);
                        }
                    }
                    else
                        MessageBox.Show("The 2.DrawRectangle() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
                }
            }
            else
                MessageBox.Show("The 1.DrawRectangle() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
        }
        else
            MessageBox.Show("The AddStandardFont() or the SetLineColor() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
    }
    else
        MessageBox.Show("The SelectPage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
    MessageBox.Show("The file can't be created.", caption);
gdpicturePDF.Dispose();
See Also