コード例 #1
0
        /// <summary>
        /// Lanzado cuando se presiona una tecla dentro del control
        /// Valida que solo ingrese numeros enteros
        /// </summary>
        /// <param name="decimalTextBox">Control TextBox</param>
        /// <param name="e">Información del Evento</param>
        private void EnterosHandled_KeyPress(CustomTextBox decimalTextBox, KeyPressEventArgs e)
        {
            int valor = 0;
            float posibleValor = 0;
            if (int.TryParse(this.Text, out valor))
            {
                valor = int.Parse(this.Text);
            }

            if (float.TryParse(e.KeyChar.ToString(), out posibleValor))
            {
                posibleValor = float.Parse(valor.ToString() + e.KeyChar.ToString());
            }

            if (this.MaxValue != 0)
            {
                if (((e.KeyChar >= '0' && e.KeyChar <= '9') && (posibleValor <= this.MaxValue)) || e.KeyChar == (char)Keys.Back)
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = true;
                }
            }
            else
            {
                if ((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == (char)Keys.Back)
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = true;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Lanzado cuando se presiona una tecla dentro del control
        /// Valida que solo se ingrese Texto
        /// </summary>
        /// <param name="decimalTextBox">Control TextBox</param>
        /// <param name="e">Información del Evento</param>
        private void SoloTextoHandled_KeyPress(CustomTextBox decimalTextBox, KeyPressEventArgs e)
        {
            if (this.IsMayusculas)
            {
                e.KeyChar = char.ToUpper(e.KeyChar);
            }

            if ((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') || e.KeyChar == (char)Keys.Back || Char.IsWhiteSpace(e.KeyChar) || e.KeyChar == 'ñ' || e.KeyChar == 'Ñ')
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }
コード例 #3
0
 /// <summary>
 /// Lanzado cuando se presiona una tecla dentro del control
 /// Valida que solo se ingrese Texto
 /// </summary>
 /// <param name="decimalTextBox">Control TextBox</param>
 /// <param name="e">Información del Evento</param>
 private void DefaultHandled_KeyPress(CustomTextBox defaultTextBox, KeyPressEventArgs e)
 {
     if (this.IsMayusculas)
     {
         e.KeyChar = char.ToUpper(e.KeyChar);
     }
 }