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 :: unity 3d sound 
Csharp :: c# sort array of objects by multiple properties 
Csharp :: if string contains number c# 
Csharp :: no move arrows unity 
Csharp :: equivalent to T extends TT in c# 
Csharp :: how to make a for loop in c# 
Csharp :: regex replace all special characters 
Csharp :: how to add b to a string in java 
Csharp :: remove all letters from string c# 
Csharp :: unity set text value 
Csharp :: how to check if control key is pressed c# 
Csharp :: dictionary c# 
Csharp :: transform.rotate unity 
Csharp :: monodevelop ubuntu 20.04 
Csharp :: Unity asset storre download forlder 
Csharp :: c# regex to find number between parenthesis 
Csharp :: C# How to change the text colour? 
Csharp :: c# shuffle array 
Csharp :: group by linq multiple columns c# 
Csharp :: c# round number 
Csharp :: c# split text by spaces 
Csharp :: c# display float with 2 decimal places 
Csharp :: frame time unity 
Csharp :: how to use file watcher in c# 
Csharp :: c# rsa example 
Csharp :: c# how to get connection string from app config 
Csharp :: get hard disk serial number 
Csharp :: Find an item in a list by LINQ 
Csharp :: how to get parent gameobject in unity 
Csharp :: topdown unity 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =