Beispiel #1
0
        private void OnLeave(object sender, System.EventArgs e)
        {
            string text = _control.Text;

            if (_mask != MaskTypes.None)
            {
                Regex rexp = new Regex(MaskHelper.GetRegExStringForMask(_mask));
                if (!rexp.IsMatch(text))
                {
                    ErrorProvider.SetError(_control, "Invalid value for " + this.Text);
                }
                else
                {
                    ErrorProvider.SetError(_control, "");
                }
            }
            else if (AnswerRequired && (_control.Text.Length > 0))
            {
                ErrorProvider.SetError(_control, "");
            }
            else if (AnswerRequired && (_control.Text.Length == 0))
            {
                ErrorProvider.SetError(_control, Text + " is a required field.");
            }

            //AFNI standard
            //If a field holds more information than can be displayed,
            //make it show the beginning of the field when the user
            //tabs off.
            _control.SelectionStart = 0;
        }
Beispiel #2
0
        private void OnKeyPress(object sender, KeyPressEventArgs kpea)
        {
            string key;
            string new_text;
            int    cursor_index;

            if (!Enabled)
            {
                kpea.Handled = true;
                return;
            }

            key = kpea.KeyChar.ToString();
            if (char.IsControl(kpea.KeyChar))
            {
                return;
            }

            if ((_allowable_chars != "") && (_allowable_chars.IndexOf(key) >= 0))
            {
                kpea.Handled = false;
            }
            else if (_allowable_chars != "")
            {
                kpea.Handled = true;
            }

            if (_mask != MaskTypes.None)
            {
                kpea.Handled = true;
                cursor_index = _control.SelectionStart;
                //text before the cursor stays the same...
                new_text = _control.Text.Substring(0, cursor_index);

                //text at the cursor is replaced
                new_text += kpea.KeyChar;

                //text past the cursor stays the same.
                if (_control.Text.Length > cursor_index)
                {
                    new_text += _control.Text.Substring(cursor_index + 1);
                }

                //kpea.Handled = !MaskHelper.FitsMask(new_text, _mask);
                _control.Text = MaskHelper.ApplyMask(new_text, _mask);

                _control.SelectionStart = cursor_index + 1;
            }
        }