HeaderPane
Main
Hide
Share Link
Print

Sample4 Sample (C#)

This sample illustrates input validation.

The source code is located at C:\Program Files (x86)\Softelvdm\SftMask OCX 8.0\Samples\Visual Studio - CSharp\Sample4\Form1.cs.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Sample4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += (s, e) => {
                foreach (Control c in Controls) {
                    AxSftMaskLib80.AxSftMask mask = c as AxSftMaskLib80.AxSftMask;
                    if (mask != null) {
                        mask.DarkMode = SftMaskLib80.SftMaskDarkModeConstants.darkSftMaskAuto; // follow the Windows dark mode setting
                        mask.HighContrastMode = SftMaskLib80.SftMaskHighContrastConstants.highContrastSftMaskAuto; // follow the Windows High Contrast setting
                    }
                }
            };
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (axSftMaskName.Contents.Valid &
                    axSftMaskCompany.Contents.Valid &
                    axSftMaskZIP.Contents.Valid &
                    axSftMaskTelephone.Contents.Valid &
                    axSftMaskDate.Contents.Valid &
                    axSftMaskAmount.Contents.Valid) {
                // save the data
                Application.Exit(); //  and exit
            } else {
                MessageBox.Show("There are validation errors - Please correct the data entered.");
            }
        }

        private void axSftMaskZIP_CustomValidation(object sender, AxSftMaskLib80._ISftMaskEvents_CustomValidationEvent e)
        {
            if (axSftMaskZIP.Text != "11111") {
                e.cancel = true;
            }
        }
    }
}

Last Updated 11/15/2026 - (email)
© 2026 Softel vdm, Inc.