Dim caption As String = "Example: GetFormFieldOnStateName"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
'Please use the PDF document created using the example from the SetFormFieldOnStateName() method.
If gdpicturePDF.LoadFromFile("test_radiobutton.pdf", False) = GdPictureStatus.OK Then
Dim count As Integer = gdpicturePDF.GetFormFieldsCount()
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
If count = 0 Then
MessageBox.Show("This file doesn't include forms.", caption)
Else
Dim formID As Integer = 0
Dim type As PdfFormFieldType = PdfFormFieldType.PdfFormFieldTypeUnknown
Dim isChecked As Boolean = False, hasRadioButtons As Boolean = False
Dim onName As String = "", userSelection As String = ""
For i As Integer = 0 To count - 1
formID = gdpicturePDF.GetFormFieldId(i)
If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
Type = gdpicturePDF.GetFormFieldType(formID)
If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
If Type = PdfFormFieldType.PdfFormFieldTypeRadioButton Then
hasRadioButtons = True
Dim rbCount As Integer = gdpicturePDF.GetFormFieldChildCount(formID)
If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
For j As Integer = 0 To rbCount - 1
isChecked = gdpicturePDF.GetFormFieldChecked(formID, j)
If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
If isChecked Then
onName = gdpicturePDF.GetFormFieldOnStateName(formID, j)
If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
userSelection = "They prefer " + onName + " colour."
Exit For 'Only one radio button is selected at a time.
End If
Next
Exit For
End If
Next
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
If Not hasRadioButtons Then
userSelection = "This file doesn't include radio buttons."
Else
userSelection = "Something goes wrong. Status: " + gdpicturePDF.GetStat().ToString()
End If
End If
MessageBox.Show(userSelection, caption)
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: GetFormFieldOnStateName";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Please use the PDF document created using the example from the SetFormFieldOnStateName() method.
if (gdpicturePDF.LoadFromFile(m_filename, false) == GdPictureStatus.OK)
{
int count = gdpicturePDF.GetFormFieldsCount();
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
if (count == 0)
MessageBox.Show("This file doesn't include forms.", caption);
else
{
int formID = 0;
PdfFormFieldType type = PdfFormFieldType.PdfFormFieldTypeUnknown;
bool isChecked = false, hasRadioButtons = false;
string onName = "", userSelection = "";
for (int i = 0; i < count; i++)
{
formID = gdpicturePDF.GetFormFieldId(i);
if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
type = gdpicturePDF.GetFormFieldType(formID);
if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
if (type == PdfFormFieldType.PdfFormFieldTypeRadioButton)
{
hasRadioButtons = true;
int rbCount = gdpicturePDF.GetFormFieldChildCount(formID);
if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
for (int j = 0; j < rbCount; j++)
{
isChecked = gdpicturePDF.GetFormFieldChecked(formID, j);
if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
if (isChecked)
{
onName = gdpicturePDF.GetFormFieldOnStateName(formID, j);
if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
userSelection = "They prefer " + onName + " colour.";
break; //Only one radio button is selected at a time.
}
}
break;
}
}
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
if (!hasRadioButtons)
userSelection = "This file doesn't include radio buttons.";
}
else
userSelection = "Something goes wrong. Status: " + gdpicturePDF.GetStat().ToString();
MessageBox.Show(userSelection, 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();