Sponsored By
MindStick SurveyManager
Advertise with Us
Advertisement
Advertise with Us
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
   

Home >> .Net >> C# >> Numeric Textbox
Author Post

Chris S


Total Post: 16
Member Since: 9/29/2010
Points: 93
Numeric Textbox
Posted On: 10/4/2010 1:56:44 PM
Hello everyone , I am trying to create my textbox as a numeric text box which can take only numeric values.
Please provide me any sample or code.

Thanks
Chris

Author Post

Uttam Misra


Total Post: 113
Member Since: 6/2/2010
Points: 818
Re: Numeric Textbox
Posted On: 10/5/2010 2:41:25 AM
Check this article Chris..

http://www.mindstick.com/Articles/6e3c047c-17aa-4ea2-b390-a8b756404f09/


private voidtextBox1_KeyPress(object sender, KeyPressEventArgs e)

        {           

if (char.IsDigit(e.KeyChar)== false && e.KeyChar != '.' && e.KeyChar!='\b')

//checking whether pressed key is number, decimal orbackspace.

//If false then we will set Handled variable ofKeyPressEventArgs to true.

//By doing this system will get a message that character of keypressed

//is executed and hence aplpa numeric character will not bedisplayed

//except decimal.

                e.Handled=true;

            elseif (e.KeyChar == '.')

                if(textBox1.Text.Contains('.'))

                    e.Handled=true;           

//checking whether decimal key is pressed or not, if truethen checking

//whether decimal is already present or not, as we can haveonly

//one decimal point in a text box.

        }


Modified On: 10/5/2010 2:41:51 AM
Report Abuse Form
Reason:    
 
Total Online Users: 2881
Advertisement
MindStick DataConverter
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.