Skip to main content
All docs
V26.1
  • RadioGroupField Class

    A radio group field is a form field that contains a set of options, only one of which can be selected.

    Namespace: DevExpress.Docs.Pdf

    Assembly: DevExpress.Docs.Pdf.v26.1.dll

    Declaration

    public class RadioGroupField :
        FormField

    The following members return RadioGroupField objects:

    Remarks

    For more information, refer to the following help topic: DevExpress PDF Document API - Form Fields.

    Example

    How to: Add a Radio Group Field to a PDF Document

    The following code snippet adds a radio button group with three options to a PDF document:

    DevExpress New PDF API library - Radio Group Field

    using DevExpress.Docs.Pdf;
    using DevExpress.Drawing.Printing;
    using System.Drawing;
    
    namespace ConsoleApp1;
    
    public class Program {
        public static async Task Main(string[] _) {
            using (PdfDocument pdfDocument = new()) {
                // Add an A4 page to the document.
                Page page = pdfDocument.Pages.Add(DXPaperKind.A4);
    
                float y = 750;
                float step = 30;
                float textHeight = 14f;
    
                // Create a radio group field and add it to the field collection.
                RadioGroupField radioGroupField = new("radioGroup");
                pdfDocument.Fields.Add(radioGroupField);
    
                // Add the first radio button widget and its label.
                RectangleF radioBounds1 = new(50, y - textHeight + 6, 18, 18);
                RadioGroupItemWidgetAnnotation radioGroupItem1 = new(radioGroupField, "Option1", radioBounds1);
                y -= step;
                page.Annotations.Add(radioGroupItem1);
    
                TextFragment label1 = new() { Text = "Option #1", Location = new PointF(radioBounds1.X + 30, radioBounds1.Y + 6) };
                page.Fragments.Add(label1);
    
                // Add the second radio button widget and its label.
                RectangleF radioBounds2 = new(50, y - textHeight + 6, 18, 18);
                RadioGroupItemWidgetAnnotation radioGroupItem2 = new(radioGroupField, "Option2", radioBounds2);
                page.Annotations.Add(radioGroupItem2);
                y -= step;
    
                TextFragment label2 = new() { Text = "Option #2", Location = new PointF(radioBounds2.X + 30, radioBounds2.Y + 6) };
                page.Fragments.Add(label2);
    
    
                // Add the third radio button widget and its label.
                RectangleF radioBounds3 = new(50, y - textHeight + 6, 18, 18);
                RadioGroupItemWidgetAnnotation radioGroupItem3 = new(radioGroupField, "Option3", radioBounds3);
                page.Annotations.Add(radioGroupItem3);
                y -= step;
    
                // Set the default selected value.
                radioGroupField.Value = "Option3";
    
                TextFragment label3 = new() { Text = "Option #3", Location = new PointF(radioBounds3.X + 30, radioBounds3.Y + 6) };
                page.Fragments.Add(label3);
    
                // Save the document to a file.
                FileStream outputStream = new FileStream(@"D:\doc.pdf", FileMode.Create);
                pdfDocument.Save(outputStream);
                outputStream.Dispose();
            }
        }
    }
    

    Implements

    Inheritance

    Object
    FormField
    RadioGroupField
    See Also