Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# textboxaccept only numbers

 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
    }
Comment

textbox only numbers c#

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
        (e.KeyChar != '.'))
    {
            e.Handled = true;
    }

    // only allow one decimal point
    if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
    {
        e.Handled = true;
    }
}
Comment

c# textbox numbers only

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
        (e.KeyChar != '.'))
    {
            e.Handled = true;
    }

    // only allow one decimal point
    if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
    {
        e.Handled = true;
    }
}
Comment

c# textbox only numbers

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
        (e.KeyChar != '.'))
    {
            e.Handled = true;
      //Handles every non digit input except paste via Crtl+V
    }

    // only allow one decimal point
    if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
    {
        e.Handled = true;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# making a folder wpf 
Csharp :: c# md5 
Csharp :: unity RemoveComponent 
Csharp :: get layermask from gameobject layer unity 
Csharp :: c# list tuple 
Csharp :: get roaming folder c# 
Csharp :: .net framework get configuration value from web.config 
Csharp :: scaffold single table to model ef core 
Csharp :: c# web api return image file 
Csharp :: const class in c sharp 
Csharp :: good food 
Csharp :: linq from select 
Csharp :: https request c# 
Csharp :: c# onmousedown. unity 
Csharp :: Unity Destroy gameObject upon collision 
Csharp :: No Entity Framework provider found for the ADO.NET provider with invariant name 
Csharp :: 3d perlin noise unity 
Csharp :: contains c# 
Csharp :: see if two string arrays are equal c# 
Csharp :: doing void when gameobject setactive unity 
Csharp :: c# for loop next iteration 
Csharp :: c# select oracle database 
Csharp :: c# get all enum values 
Csharp :: update multiple records with entity framework 
Csharp :: .net core check if linux 
Csharp :: get sha1 of file c# 
Csharp :: datatable linq where clause c# 
Csharp :: how to set picturebox width with form width in c# 
Csharp :: c# readline char 
Csharp :: unity switch 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =