Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 18th, 2004, 08:56 AM
Registered User
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simple Question

Dear all,

I was a new programmer that using C#, here are one stupid question to ask.

How can I set a textbox to only allow a numeric value up to 2 decimal place.

Thanks for help

MSK




 
Old July 18th, 2004, 11:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

u have 2 steps.
1_ First u should check ur pressed Key, so do it as
Code:
textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
Then in ur textBox1_KeyPress put following codes;

Code:
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    if( (e.KeyChar > 57 | e.KeyChar < 48) )
        e.Handled = true;
}
2_ for makeing limit for lenght of ur textbox set MaxLength to 2

HTH

Always:),
Hovik Melkomian.
 
Old July 19th, 2004, 10:28 AM
Authorized User
 
Join Date: May 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fantastic!

niuwei
 
Old July 29th, 2004, 10:21 PM
Registered User
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your help!

But if I want to force user only input only up to 100000.00 and need to add a "," in thousand place, how can I do.

Rich

 
Old August 1st, 2004, 12:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Well since its a Window App. u can have .NET powerful Validation control too.
for more info see http://search.microsoft.com/search/r...&c=0&s=1&swc=0 & keep in touch in faced problem.

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Very Simple Question YoungLuke C# 2 May 4th, 2007 02:23 AM
Simple Question ironchef Java GUI 0 September 14th, 2006 04:56 PM
Simple Question dpkbahuguna Java Basics 2 May 19th, 2006 12:05 AM
Simple question happyheart_man Pro VB.NET 2002/2003 0 January 14th, 2004 11:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.