Get form field name on click

I've added this:

private void pdfViewerMappings_FormFieldClicked(object sender, FormFieldClickedEventArgs args)

but I can't figure out how to get the name of the field that was clicked on.


3 Replies 1 reply marked as answer

KG Krithika Ganesan Syncfusion Team February 12, 2024 01:03 PM UTC

In the WPF PdfViewer, you can retrieve the form field name by typecasting the FormField property of the FormFieldClickedEventArgs to the respective control. We have attached a sample and a code snippet demonstrating how to retrieve the name for all supported form fields using the FormFieldClicked event of PdfViewerControl.


UG link: https://help.syncfusion.com/wpf/pdf-viewer/form-filling-in-pdf#retrieve-the-form-field-details


private void PdfViewerControl_FormFieldClicked(object sender, Syncfusion.Windows.PdfViewer.FormFieldClickedEventArgs args)

{

    if (args.FormField is TextBox)

    {

        //Typecast the `FormField` property to `System.Windows.Controls.TextBox`

        TextBox text = args.FormField as TextBox;

        String name = text.Name;

    }

    else if (args.FormField is PasswordBox)

    {

        //Typecast the `FormField` property to `System.Windows.Controls.PasswordBox`

        PasswordBox PasstextBox = args.FormField as PasswordBox;

        String name = PasstextBox.Name;

    }

    else if (args.FormField is ListBox)

    {

        //Typecast the `FormField` property to `System.Windows.Controls.ListBox`

        ListBox listBox = args.FormField as ListBox;

        String name = listBox.Name;

    }

    else if (args.FormField is ComboBox)

    {

        //Typecast the `FormField` property to `System.Windows.Controls.ComboBox`

        ComboBox comboBox = args.FormField as ComboBox;

        String name = comboBox.Name;

    }

    else if (args.FormField is CheckBox)

    {

        //Typecast the `FormField` property to `System.Windows.Controls.CheckBox`

        CheckBox checkBox = args.FormField as CheckBox;

        String name = checkBox.Name;

    }

    else if (args.FormField is RadioButton)

    {

        //Typecast the `FormField` property to `System.Windows.Controls.RadioButton`

        RadioButton radiobtn = args.FormField as RadioButton;

        String name = radiobtn.Name;

    }

}


Attachment: PdfViewerWPF_79fe144.zip

Marked as answer

KA Keith A Price February 12, 2024 04:30 PM UTC

Awesome! Thanks so much.



KG Krithika Ganesan Syncfusion Team February 13, 2024 06:49 AM UTC

Most welcome, please get back to us for any further assistance.


Loader.
Up arrow icon