Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

windows form textbox numbers only

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "[^0-9]"))
    {
        MessageBox.Show("Please enter only numbers.");
        textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
    }
}
Comment

windows form textbox only allow numbers

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

PREVIOUS NEXT
Code Example
Csharp :: month number to text in c# 
Csharp :: c# iformfile to string 
Csharp :: subtract two times c# 
Csharp :: c# round to 2 decimal places 
Csharp :: Add float value to ui text in unity 
Csharp :: c# exit 
Csharp :: unity gameobject.findobjectswith tag set active 
Csharp :: c# int to byte array 
Csharp :: db scaffolding ef core 
Csharp :: dynamics 365 update record c# 
Csharp :: c# 8 null coalescing assignment 
Csharp :: game object disapear after transform.position 
Csharp :: unity particle system playing at the wrong location 
Csharp :: check c# date for 0001/01/01 
Csharp :: tooltip button winform 
Csharp :: how to be like bill gates 
Csharp :: c# multiline string with variables 
Csharp :: remove whitespace between string c# 
Csharp :: shorthand in c# operator 
Csharp :: unity2d click on gameobject 
Csharp :: uni valued tree 
Csharp :: unity set active for seconds 
Csharp :: unity put children in list 
Csharp :: unity object to mouse position 
Csharp :: unity read from text file 
Csharp :: how to get the path of the current directory in c# 
Csharp :: c# solution path 
Csharp :: c# read file from path 
Csharp :: c# odd even median 
Csharp :: reverse for loop 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =