The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

How to: Create a Checkbox

  • 2 min to read

Follow the steps below to create a CheckBox object in code:

  1. Access the document's form fields collection using the SubDocument.FormFields property and call the FormFieldCollection.InsertCheckBox method to create a CheckBox object at the specified document position. In the example below, the checkbox is created at the caret's position.

    Note

    Checkboxes cannot be inserted to the document header, footer, comments or floating objects (text boxes or shapes). Otherwise, an FormFieldIncorrectSubDocumentException occurs.

  2. Define the name of the bookmark associated with the current CheckBox object using the FormField.Name property.
  3. Specify the checkbox's state using the CheckBox.State property.
  4. Use the CheckBox.SizeMode property to define the checkbox's size. Selecting the CheckBoxSizeMode.Auto mode resizes the checkbox according to the current font size value (returned by the CharacterPropertiesBase.FontSize property). Set the SizeMode property to CheckBoxSizeMode.Exact and specify the CheckBox.Size value to specify the checkbox's size.
  5. You can add instructional text to the checkbox. This text can be displayed in the status bar or when focusing the checkbox and pressing F1. Specify the help text type and the text using the following members:

    When setting the HelpTextType or StatusTextType property to FormFieldTextType.Auto, make sure that the provided HelpText or StatusText value is equal to one of the AutoText gallery's entries (stored as the Normal.dotm file in the system's Templates folder). Otherwise, the help text is not displayed.

    Note

    Currently, the RichEditControl cannot display any instructional text.

  6. Set the FormField.CalculateOnExit property to true to update the checkbox's value on exit.
DocumentPosition currentPosition = server.Document.CaretPosition;
DevExpress.XtraRichEdit.API.Native.CheckBox checkBox = server.Document.FormFields.InsertCheckBox(currentPosition);
checkBox.Name = "check1";
checkBox.State = CheckBoxState.Checked;
checkBox.SizeMode = CheckBoxSizeMode.Auto;
checkBox.HelpTextType = FormFieldTextType.Custom;
checkBox.HelpText = "help text";