Howto: Deploy and Validate Forms

This chapter shows how to deploy created form documents using a Windows Forms UI that helps users to complete and validate form fields. This sample uses the same sample form template that is discussed in the technical article Creating Conditional Instructions for Form Fields.

The source code for this example is contained in the following directories:

  • %USERPROFILE%\Documents\TX Text Control 29.0.NET for Windows Forms\Samples\WinForms\VB.NET\FormFields\FormField_DeployNValidate
  • %USERPROFILE%\Documents\TX Text Control 29.0.NET for Windows Forms\Samples\WinForms\CSharp\FormFields\FormField_DeployNValidate

Used TX Text Control controls:

  • TXTextControl.TextControl

Relevant API links:

Creating a Read-Only Form Completion UI

In order to deploy a form, TX Text Control provides a special read-only mode for end-users to complete form fields. In this edit mode, content is read-only and form fields can be completed by end-users. Additionally, the form field logic in form of the connected conditional instructions is applied and executed.


In order to switch to this form completion mode, the AllowEditingFormFields property and the Read Only property must be set to true and the TextControl.EditMode property needs to be set to EditMode.ReadAndSelect.

private void EnableFormFieldsProtection() {
 textControl.DocumentPermissions.ReadOnly = true;
 textControl.DocumentPermissions.AllowEditingFormFields = true;
 textControl.EditMode = TXTextControl.EditMode.ReadAndSelect;
Private Sub EnableFormFieldsProtection()
 TextControl.DocumentPermissions.ReadOnly = True
 TextControl.DocumentPermissions.AllowEditingFormFields = True
 TextControl.EditMode = TXTextControl.EditMode.ReadAndSelect
End Sub

On initializing TextControl, the existing form field ribbon tab is customized by removing groups that are built for the form creation process. Only the groups to highlight the form fields and to highlight the invalid values are kept. Additionally, a new ribbon group is added to validate and finish the form completion.

The following code shows the Form Load event that is used to load the form template, customize the ribbon and to switch to the read-only form completion mode:

private void Form1_Load(object sender, EventArgs e) {
 ribbon.HasApplicationMenu = false;
 textControl.Load("travel-form.tx", StreamType.InternalUnicodeFormat);
    RibbonFormFieldsTab.RibbonItem.TXITEM_HighlightInvalidValues) as RibbonToggleButton).Checked = true;

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 ribbon.HasApplicationMenu = False
 TextControl.Load("travel-form.tx", StreamType.InternalUnicodeFormat)
 Dim btnHighlightInvalidValues As RibbonToggleButton =
 btnHighlightInvalidValues.Checked = True

End Sub

After starting the application, invalid fields are highlighted in yellow. When clicking the Validate Document button at this time, a message box warning is opened explaining that the document is not valid according to the conditional instruction rules.


The following code shows how to iterate through the fields to check the validity of the conditional instructions:

foreach (FormField ff in textControl.FormFields) {
 if (!textControl.FormFields.ConditionalInstructions.HasValidValue(ff)) {
     MessageBox.Show(this, Resources.MSG_INVALIDDOCUMENT_TEXT,
For Each ff As FormField In textControl.FormFields
 If (Not textControl.FormFields.ConditionalInstructions.HasValidValue(ff)) Then
     Exit Sub
 End If


In case, all conditional instruction rules are fulfilled and the document is valid, a positive message box informs the user about this state.