نمایش نتایج 1 تا 40 از 534

نام تاپیک: 1001 نکته در سی شارپ

Threaded View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #8

    Cool تعدادی کد اعتبارسنجی(Validation) برای TextBox

    TextBox عددی

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

    TextBox عددی با اعشار

    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 فقط کاراکنری

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

    TextBox برای فقط حروف بزرگ

    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if ( !( char.IsUpper( e.KeyChar ) || char.IsControl( e.KeyChar )) )
    {
    e.Handled = true;
    }
    }
    TextBox برای فقط حروف کوچک

    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if ( !( char.IsLower( e.KeyChar ) || char.IsControl( e.KeyChar )) )
    {
    e.Handled = true;
    }
    }
    چک کردن TextBoxهای خالی (می‌توانید کلیه TextBox های روی فرمتان را به آن ارسال کنید )

    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;
    }
    TextBox اعشاری(با علامت اعشار مربوط به هر منطقه)

    string DecimalSeparator = Thread.CurrentThread.CurrentCulture.NumberFormat.N umberDecimalSeparator;
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if ( !( char.IsDigit( e.KeyChar) || char.IsControl( e.KeyChar ) || (DecimalSeparator.IndexOf(e.KeyChar) != -1 ) ) )
    {
    e.Handled = true;
    }
    }

    منبع : مقداری ‍CodeProject
    آخرین ویرایش به وسیله Mahmoud.Afrad : چهارشنبه 17 تیر 1394 در 14:23 عصر

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •