private void textControl1_TextFieldClicked(object sender, TXTextControl.TextFieldEventArgs e)
 {
     TXTextControl.ApplicationField appField = (TXTextControl.ApplicationField)e.TextField;
     ApplicationFieldActivate(appField);
 }
        private void ApplicationFieldActivate(TXTextControl.ApplicationField ApplicationField)
        {
            // remove all child controls
            textControl1.Controls.Clear();

            // check the field type in order to display the proper control
            switch (ApplicationField.TypeName)
            {
            case "FORMDROPDOWN":
                // create a FormDropDown field
                FormDropDown fddField = new FormDropDown(ApplicationField);

                // create a new System.Windows.Forms.ComboBox and add the
                // FormDropDown's items
                ComboBox cb = new ComboBox();

                cb.Items.AddRange(fddField.ListEntries.ToArray <string>());

                Point cbLocation = new Point((fddField.ApplicationField.Bounds.Location.X -
                                              textControl1.ScrollLocation.X) / dpiX,
                                             (fddField.ApplicationField.Bounds.Location.Y -
                                              textControl1.ScrollLocation.Y) / dpiX);

                cb.Location              = cbLocation;
                cb.Tag                   = fddField;
                cb.SelectedText          = fddField.ApplicationField.Text;
                cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
                cb.LostFocus            += new EventHandler(cb_LostFocus);

                // show the ComboBox on top of TextControl
                textControl1.Controls.Add(cb);
                cb.Focus();

                break;

            case "FORMCHECKBOX":
                // create a FormCheckBox field
                FormCheckBox fcbField = new FormCheckBox(ApplicationField);

                fcbField.Checked = !fcbField.Checked;
                // change the text according to the current state
                fcbField.Text = fcbField.Checked == true ? CHECKED : UNCHECKED;
                break;

            case "DATE":
                // create a DateField field
                DateField dField = new DateField(ApplicationField);

                // create a new System.Windows.Forms.DateTimePicker and set the
                // date to the current DateField date
                DateTimePicker dtPicker = new DateTimePicker();
                dtPicker.Tag   = dField;
                dtPicker.Value = DateTime.Parse(dField.Text);

                Point dtpLocation = new Point((dField.ApplicationField.Bounds.Location.X -
                                               textControl1.ScrollLocation.X) / dpiX,
                                              (dField.ApplicationField.Bounds.Location.Y -
                                               textControl1.ScrollLocation.Y) / dpiX);

                dtPicker.Location = dtpLocation;

                dtPicker.ValueChanged += new EventHandler(dtPicker_ValueChanged);
                dtPicker.LostFocus    += new EventHandler(dtPicker_LostFocus);

                // show the DateTimePicker on top of TextControl
                textControl1.Controls.Add(dtPicker);
                dtPicker.Focus();

                break;

            case "FORMTEXT":
                // create a FormText field
                FormText ftField = new FormText(ApplicationField);

                // create a new System.Windows.Forms.TextBox and set the
                // text to the current FormText text
                TextBox tb = new TextBox();

                tb.Text      = ftField.Text;
                ftField.Text = "";

                Point tbLocation = new Point((ftField.ApplicationField.Bounds.Location.X -
                                              textControl1.ScrollLocation.X) / dpiX,
                                             (ftField.ApplicationField.Bounds.Location.Y -
                                              textControl1.ScrollLocation.Y) / dpiX);

                tb.Location   = tbLocation;
                tb.Tag        = ftField;
                tb.LostFocus += new EventHandler(tb_LostFocus);
                tb.KeyPress  += new KeyPressEventHandler(tb_KeyPress);
                tb.SelectAll();

                // show the TextBox on top of TextControl
                textControl1.Controls.Add(tb);
                tb.Focus();
                break;
            }
        }