473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

A newby question. Please help

Hi,
The problem is laughably simple: I have a text box which must accept only
numbers (on aim to restrict some extremely "talented" users to write, for
example "blahblahblah" instead of 234); In C++ that is not a problem. As soon
as you link some variable with dialog item, for example link a text box with
some integer, the compiler restricts user to enter any char in above box,
except numeric. in more subtle cases, one may use IsAlpha, IsAlnim and other
functions to make decision.
I am new to C# and still can not find the easy way. The only way I managed
to find, is to override OnKeyDown function, check character by myself and
allow only right ones.
Can anybody tell an easier way?
Nov 16 '05 #1
3 1149
This is the way to do it if you want the user to experience nothing but
digits typing in the text box.

Or you can allow the user to type anything they want but then use the
Validating event to warn them of bad content. It all depends upon the
user experience you want to offer.

If you're going to do it using OnKeyDown, then just create a subclass
of TextBox called, say, TextBoxNumeric, and then drop that on your
form. Then you can reuse it.

I think that we're all gradually building libraries of special-purpose
input controls, that we may all soon throw away, becuase I believe that
the 2.0 .NET framework includes a text box with an input mask property,
so that you can specify in mask form what the text box should accept.

Nov 16 '05 #2
You're on the right track if this is really what you need to do. But if I
were you, I'd ask myself if maybe I wanted to use a NumericUpDown control
rather than a TextBox control. If you really just need numbers, you're
going to an awful lot of extra trouble...

"Default" <De*****@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
Hi,
The problem is laughably simple: I have a text box which must accept only
numbers (on aim to restrict some extremely "talented" users to write, for
example "blahblahblah" instead of 234); In C++ that is not a problem. As
soon
as you link some variable with dialog item, for example link a text box
with
some integer, the compiler restricts user to enter any char in above box,
except numeric. in more subtle cases, one may use IsAlpha, IsAlnim and
other
functions to make decision.
I am new to C# and still can not find the easy way. The only way I managed
to find, is to override OnKeyDown function, check character by myself and
allow only right ones.
Can anybody tell an easier way?

Nov 16 '05 #3
I will not recommend stopping the characters entering, I would rather
validate it to be a number and show the little error provider error if
invalid. If you want your numeric textbox... apart from the things mentioned
by others, you will also need to override the default context menu (and Ctrl
+ V) to stop people pasting text into it. I have seen people override the
context menu by creating the new contextmenu without any entries. This gets
rid of the copy context menu as well which is quite annoying.

"Default" <De*****@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
Hi,
The problem is laughably simple: I have a text box which must accept only
numbers (on aim to restrict some extremely "talented" users to write, for
example "blahblahblah" instead of 234); In C++ that is not a problem. As
soon
as you link some variable with dialog item, for example link a text box
with
some integer, the compiler restricts user to enter any char in above box,
except numeric. in more subtle cases, one may use IsAlpha, IsAlnim and
other
functions to make decision.
I am new to C# and still can not find the easy way. The only way I managed
to find, is to override OnKeyDown function, check character by myself and
allow only right ones.
Can anybody tell an easier way?

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Damien | last post by:
I have just built a simple stopwatch application, but when i f5 to get things goings i get this message, An unhandled exception of type 'System.ArithmeticException' occurred in...
0
by: Pete | last post by:
Hi All, A total Newby with, possibly, a daft question? However, until I can get a reasonable explanation I am disinclined towards going further. Here goes: I recently downloaded the latest...
20
by: Jack Schitt | last post by:
I thought I was starting to get a handle on Access, until I tried doing something useful...now I'm stuck. I have a DB with two tables - to keep it simple I'll say that one is an Employee File...
10
by: Fred Nelson | last post by:
Hi: I have programmed in VB.NET for about a year and I'm in the process of learing C#. I'm really stuck on this question - and I know it's a "newby" question: In VB.NET I have several...
5
by: Damien | last post by:
Heu guys, I have just built a simple stopwatch application, but when i f5 to get things goings i get this message, An unhandled exception of type 'System.ArithmeticException' occurred in...
4
by: Fred Nelson | last post by:
Hi: I'm developing a web application that needs to have five values, each retrieved from cookies on many pages. If I have five "Request.Cookies" commands together does this cause five "round...
2
by: Fred Nelson | last post by:
Hi: I'm working on a VS2005 web application and I have what is probabably a "newby" question. In VS2003 I could drag a textbox/button/etc on to a form and position it with the mouse. I...
2
by: johnnyG | last post by:
Greetings, I'm studying for the 70-330 Exam using the MS Press book by Tony Northrup and there are 2 side-by-side examples of using the SHA1CryptoServiceProvider to create a hash value from a...
2
by: Jeff | last post by:
I'm new to vb.net web developer 2005. I assume that this is the correct web site for this question, but please let me know if there is another that is better. I'm having difficulty finding the...
5
by: alexrixhardson | last post by:
Hi guys, I am a newby in the C/C++ world, and I am beginning to work on a rather simple TCP/IP proxy application which must be able to handle large volume of data as quickly as possible. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.