• Some useful TextBox Validations


    Numeric TextBox
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if ( !( char.IsDigit( e.KeyChar ) || char.IsControl( e.KeyChar ) ) )
    {
    e.Handled = true;
    }
    }
    

    Numeric TextBox with Decimals
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if ( !( char.IsDigit( e.KeyChar) || char.IsControl( e.KeyChar ) ||(e.KeyChar== (char )46)) )
    {
    e.Handled = true;
    }
    }
    

    TextBox Allowing Characters Only
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if ( !( char.IsLetter( e.KeyChar ) || char.IsControl( e.KeyChar ) ) )
    {
    e.Handled = true;
    }
    }
    

    TextBox Allowing Upper Case Characters Only
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if ( !( char.IsUpper( e.KeyChar ) || char.IsControl( e.KeyChar )) )
    {
    e.Handled = true;
    }
    }
    

    TextBox Allowing Lower Case Characters Only
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if ( !( char.IsLower( e.KeyChar ) || char.IsControl( e.KeyChar )) )
    {
    e.Handled = true;
    }
    }
    

    Check For Unfilled TextBox
    // Call this function and pass the Textbox as parameter to this function
    public static bool ChkEmpty(params System.Windows.Forms.TextBox[ ] tb)
    {
    int i;
    for (i = 0; i < tb.Length; i++)
    {
    if (tb[i].Text.Trim() == "")
    {
    MessageBox.Show("Don't keep field empty");
    tb[i].Focus();
    return false;
    }
    }
    return true;
    }


    http://www.codeproject.com/useritems/tips.asp#tip3.4.3
     
  • 相关阅读:
    光照模型
    多线程编程(7)Semaphore信号量
    多线程编程(3)
    Oracle SQL*plus常用的命令和函数
    经典的开发工具
    Windows 7/Vista下通过组策略禁止USB接口
    浅谈.NET下的多线程
    SQLServer和Oracle常用函数对比
    注册表操作类
    利用using和try/finally语句来清理资源
  • 原文地址:https://www.cnblogs.com/ipqn/p/381776.html
Copyright © 2020-2023  润新知