Click here to Skip to main content
15,917,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to change the color of my text box of any one enters the alphabet and want to allow only numeric value....

[edit]Changed title from "Help me" to more descriptive[/edit]
Posted
Updated 13-Mar-10 23:16pm
v2

You need to validate what is entered onKeyPress.

Handle the event, change the color and restrict user as per you want.
Sample:
C#
private void txtBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    // Validates integers n float
    if ((e.KeyChar > 47 && e.KeyChar < 58) || (e.KeyChar == 46) || (e.KeyChar == 8))
    {
      //Your logic here if needed
    }
    else
    {
      // Change the Color or show message 
      // MessageBox.Show("Please enter valid integer.");
    }
}
 
Share this answer
 
Please do not post questions with titles like "help me" or "help needed" - try to be descriptive as it both encourages those who know about your problem to answer, and doesn't waste the time of those who don't!
I changed yours to show you what I mean.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900